当我通过简单的 javascript 函数更改值时,ng-if 不起作用。我的函数被调用,但在视图中看不到值的变化。请参考下面的代码。
HTML
<div id="span" ng-app='MyModule' ng-cloak ng-controller="MyController">
<div ng-if="!bool">
This is for true
</div>
<div ng-if="bool">
This is False
</div>
{{bool}}
<br>
<input type="submit" ng-click = "myfunction('test')" value="ng-if button">
</div>
<input type="submit" onClick = "check1()" value="simple JS button">
JS
angular.module('MyModule', [])
.controller('MyController', function ($scope) {
$scope.bool = true;
$scope.myfunction = function (data) {
$scope.bool = !$scope.bool;
};
});
function check1() {
angular.element(document.getElementById('span')).scope().myfunction('test');
}
当我使用ng-click button
它时,它会更改更改的值bool
,但simple JS button
. 实际上我正在一个已经使用 jQuery 的页面中实现 Angular,所以我需要使用simple JS button
.
JS 小提琴:JS 小提琴