为什么我无法添加新项目? 当我在模块[]中添加时 - 它不起作用。
var app = angular.module('myApp', []);
app.controller('addItemCtrl',
['$scope', function($scope) {
$scope.items = [];
$scope.additem = function() {
$scope.items.push({'title': $scope.newItem, 'done':false})
$scope.newItem = '';
}
$scope.deleteitem = function(index) {
$scope.items.splice(index, 1);
} }])
答案 0 :(得分:0)
您是否拥有执行这些功能的UI部分?
例如:https://plnkr.co/edit/7dA2IhINdgTe90ftyMt9?p=preview
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>
<script src="app.js"></script>
</head>
<body ng-controller="addItemCtrl">
<p>Count {{items.length}}</p>
<button ng-click="additem()">Add Item</button>
<button ng-click="deleteitem()">Delete Item</button>
</body>
</html>