angularJS为什么是$scope ?我的手表坏了
angularJS why $scope.$watch cant't work?
我想添加一个$watch到watch $scope。数据被更改或未更改,但它不能工作
[http://jsbin.com/biqesojaqu/1/edit?html, js、控制台、输出][1]
app.html
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body ng-app="App" ng-controller="TestController">
<div>
<ul>
<li ng-repeat="item in data"> {{ item.name }}--{{ item.status }}</li>
<button ng-click="addOnePerson()">ADD</button>
</ul>
</div>
</body>
</html>
app.js
var App = angular.module("App", []);
App.controller('TestController', function ($scope) {
$scope.data = [
{name: 'cc', status: true},
{name: 'bob', status: false}
];
$scope.name = 'nataila';
$scope.addOnePerson = function () {
var personCount = $scope.data.length;
personCount += 1;
$scope.data.unshift({name: 'cc'+personCount, status: true});
};
$scope.$watch('data', function (){
console.log('has changed');
});
});
当我点击按钮时,我以为控制台会输出has chenged
,但是没有请告诉我为什么,这是很好的帮助我在JSbin
用$watchCollection
代替array
或object
$scope.$watchCollection('data', function (){
console.log('has changed');
});
JSBin
相关文章:
- 为什么不't Javascript对我的输入值进行了一些重新检查
- 可以't让我的if语句处理js中的html表单输入
- 我的单元测试选项是什么
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 我的职位回报太快了,如何做出承诺
- 我的jQuery插件参数没有正确启动,遇到了问题
- 如何识别我的网站中的慢速设备
- 如何将JSON数据导入我的ejs模板
- JQuery添加元素需要在我的js之前再次添加JQuery脚本
- 知道为什么我的旋转木马不会自动更改图片吗
- 我的模板未被解析
- 无法将数据从firebase获取到我的html页面
- 角度图表;t显示在我的页面中
- $scope$Angular中的手表;我不在爱奥尼亚/科尔多瓦工作
- GULP 手表在我的 gulp.js 文件中不起作用
- Angular scope手表;在我的应用程序中不起作用
- Typescript -w(手表)不工作在我的安装
- 我如何在javascript中创建自己的手表函数,类似于angular
- AngularJS:为什么我的手表不走了?
- angularJS为什么是$scope ?我的手表坏了