【发布时间】:2014-08-11 03:42:07
【问题描述】:
从 angularjs 开始,这个问题让我很困惑。
如何以及如何确保当 watch 函数第二次运行时(在初始化时)testValue 被“更改”。
<div ng-controller="MyCtrl"></div>
和js:
var myApp = angular.module('myApp',[]);
function MyCtrl ($scope) {
var testValue = null;
$scope.watchMe = null;
$scope.$watch('watchMe', function () {
console.log('testValue is', testValue);
if(testValue !== null){`enter code here`
console.log('i want to do something different the 2nd time this code runs - but i never get in here...');
}
testValue ="changed";
});
};
然后是小提琴:jsfiddle example of the code
非常感谢
【问题讨论】:
-
角度太难了
标签: javascript angularjs