我正在嘗試我的第一個角度js列表示例。具有顯示列表中的問題,也有在控制檯:(列表不顯示在角度綁定?
HTML沒有錯誤
<body ng-controller="mycontroller">
<form ng-submit="addtask()">total nr of tasks: {{myvar.length}}
<br />remaining: {{remaining()}}
<input type="text" ng-model="newtask" />
<ul ng-repeat="var in myvar">
<li>
<input type="checkbox" ng-model="myvardone" /> <span class="done-{{myvardone}}">{{var.text}}</span>
</li>
</ul>
<button type="submit">add</button>
</form>
</body>
腳本:
function mycontroller($scope) {
$scope.myvar = [{
text: 'bert',
done: false
}, {
text: 'ed',
done: true
}, {
text: 'pet',
done: false
}];
$scope.addtask = function() {
$scope.myvar.push({
text: $scope.newtask,
done: false
});
}
$scope.remaining = function() {
var count = 0;
angular.forEach($scope.myvar, function (t) {
if (t.done) {
count++
} else {
count += 0;
}
});
return count;
}
}
的jsfiddle:http://jsfiddle.net/dingen2010/vc2bC/3/
http://jsfiddle.net/vc2bC/5/ –
您必須添加'NG-應用= 「對myApp」'和'angular.module( '對myApp',[ ]);'引導角 –
剩下的數字,即非strikentrhough任務不工作,雖然? – user603007