我想使用java腳本函數更改ng-show條件。AngularJS:如何使用java腳本函數更改span的ng顯示條件
<span id="error1" ng-show="formerror"><font color="red">{{formerror}}</font></span>
我能夠得到跨度ATTR使用
var scope4 = angular.element($("#error1"))
我想使用java腳本函數更改ng-show條件。AngularJS:如何使用java腳本函數更改span的ng顯示條件
<span id="error1" ng-show="formerror"><font color="red">{{formerror}}</font></span>
我能夠得到跨度ATTR使用
var scope4 = angular.element($("#error1"))
你可以做到這一點,但我懷疑這是從它的外角應用程序內部操縱非常好的主意。但這是可能的。
您不需要屬性,您只需訪問元素的範圍並更改它的屬性formerror
。您可以使用angular.element
的scope
方法。例如:
var $scope = angular.element($("#error1")).scope();
$scope.formerror = 'Fill in required fields.';
$scope.$apply();
謝謝dfsq。我可以直接將ng-show值設置爲false嗎? – SagarVimal 2015-04-03 18:59:24
你的意思是「真的」?是的,就像這個http://plnkr.co/edit/iyw30hy8Y5T3w8yuVrKL?p=preview。但是如果你想設置屬性值也是可能的,但我會避免它,它需要節點重新編譯。但可能。 – dfsq 2015-04-03 19:02:06
你想從角應用的外部改變的條件? – dfsq 2015-04-03 18:51:32
@dfsq是的,我在bootstrap模式中使用這個,我必須在隱藏模型時使這個條件爲false(在'hidden.bs.modal'事件上)。 – SagarVimal 2015-04-03 18:54:29