Two way binding for ng-click directive in angularjs
我在两个元素中调用了一个函数。 当我触发该函数的单击事件时,无论我在哪里调用该函数,都应该再次击中该事件。
// html
1 2 3 | <button type="button" ng-click="{{myFunction()}}">click Me !!</button> <p ng-show="{{myFunction()}}">{{name}} </p> |
//控制器
1 2 3 4 5 6 | myApp.controller('myController', function ($scope) { $scope.name = 'Helow World!'; $scope.myFunction = function(){ return true; }; }); |
我也尝试使用
1 2 3 | <button type="button" ng-click="myFunction()">click Me !!</button> <p ng-show="myFunction()">{{name}} </p> |
问题:
该功能将仅触发一次。 显示我的
解
我可以将范围对象用于
题
我的问题是,如何为
您要解决这个错误。
angular指令可与angular表达式一起使用,这意味着您可以插入任何内容,例如
因此,当您使用如下代码:
1 | $scope.myFunc = function() { return true; }; |
然后在每个摘要上执行此函数,并将
您的要求无法完成。 Angular不能那样工作。 您陈述的解决方案
I can use a scope object to Show|hide the p tag. But that's not my question.
是您最好的选择。