【问题标题】:There is angular directive for "if bool cal f()"?“if bool cal f()”有角度指令吗?
【发布时间】:2014-12-28 15:03:07
【问题描述】:

如何检查变量(我通过指令获得)以及它的值是否为真 - 调用函数?

例如:我在指令模板中有:

<a href="" ng-repeat="i in items" ng-click="i.exec()">

我想添加类似:ng-if-true-then-call="i.foo?bar()" 这样如果 i.foo 为 true -> 指令控制器的功能栏将运行。 (项目 var 来自指令的配置

<direct items="items"> 

范围是

scope: {
        items: '=',
}

我需要为此做新的指令,或者我可以使用任何现有的工具吗?谢谢!

【问题讨论】:

  • 实际上您可以将i 传递给您的函数并在您的函数中执行逻辑
  • 你能给我们一个具体的例子来说明你正在尝试做什么(不使用像“foo”和“bar”这样的名字)吗?我认为你走错了路

标签: angularjs angularjs-directive angularjs-scope


【解决方案1】:

你的指令模板:

<a href="" ng-repeat="i in items" ng-click="exec(i)">

在您的控制器中:

scope.exec = function (i) {
    if (i.foo) {
        bar();
    }
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-05
    • 2018-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多