1.angular watchå¯ä»¥çå¬å¤ä¸ªå¼ä¹
2.angularjs watchåªè½çå¬ng-modelå
angular watchå¯ä»¥çå¬å¤ä¸ªå¼ä¹
$watchç®å使ç¨
$watchæ¯ä¸ä¸ªscopeå½æ°ï¼ç¨äºçå¬æ¨¡åååï¼å½ä½ ç模åé¨ååçååæ¶å®ä¼éç¥ä½ ã
$watch(watchExpression,源码涨停预测源码 listener, objectEquality);
æ¯ä¸ªåæ°ç说æå¦ä¸ï¼
watchExpressionï¼çå¬ç对象ï¼å®å¯ä»¥æ¯ä¸ä¸ªangular表达å¼å¦'name',æå½æ°å¦function(){ return $scope.name}ã
listener:å½watchExpressionååæ¶ä¼è¢«è°ç¨çå½æ°æè 表达å¼,å®æ¥æ¶3个åæ°ï¼newValue(æ°å¼), oldValue(æ§å¼), scope(ä½ç¨åçå¼ç¨)
objectEqualityï¼æ¯å¦æ·±åº¦çå¬ï¼å¦æ设置为true,å®åè¯Angularæ£æ¥æçæ§ç对象ä¸æ¯ä¸ä¸ªå±æ§çåå. å¦æä½ å¸æçæ§æ°ç»ç个å«å ç´ æè 对象çå±æ§èä¸æ¯ä¸ä¸ªæ®éçå¼, é£ä¹ä½ åºè¯¥ä½¿ç¨å®
angularjs watchåªè½çå¬ng-modelå
$scope对象èªå¨å°è£ çï¼åªè¦å称ä¸è´å°±è¡äºæ¯å¦ï¼ng-model="name",$scope.nameå°±è½æ¿å°å¼äº