ng-href中的AngularJs if语句 [英] AngularJs if statement in ng-href

查看:77
本文介绍了ng-href中的AngularJs if语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些动态创建的元素,每个元素都有不同的ng-href.

I have some elements which are created dynamically and every element has a different ng-href.

我想根据某些元素提供不同的链接.

I want to give different link according to some elements.

当我尝试在ng-href中编写函数时,它会将页面发送到url中的函数,因此它不起作用.

When I try to write function in ng-href it sends the page to function in url,therefore it does not work.

我试图做这样的事情;

I try to do something like this;

       .......
             <a 
            ng-href='if(m){#linkOne} else {#linkTwo}'
            ng-click='test(type);'>

              </a> 
       .......

我应该使用哪种方法来创建具有不同ng-href的元素?

Which method should i use to create element with different ng-href?

推荐答案

您可以尝试

<a ng-href="{{m ? '#linkOne':'#linkTwo'}}" ng-click="test(type)">your link</a>

http://jsfiddle.net/54ema4k0/

这篇关于ng-href中的AngularJs if语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆