学习angularjs时遇到 XX is not a function

出现这个问题是因为在 angularJs 1.3 中 为了让 根节点上(rootScope)不再被挂上许多冗余的内容,所以禁止了直接在根上注册controller。

第一:以后不能直接以  function XXXcontroller (){ code......}这样的方式直接注册监听器了。以后必须

angular.module('phonecatApp', []).controller('PhoneListCtrl',function($scope) {}这样来将controller注册到对应的模型上。

第二:  在 ng-aap 中指定相对应的模型。

如 之前:

<html ng-app>(不指定则为根元素)

现在:

<html ng-app="phonecatApp">

<DOCTYPE html>
<html ng-app="HelloApp">
<head>
<title>test</title>
<script src="../../angular.js"></script>
</head>
<body ng-controller="CartController">
<h1>your Order</h1>
<div ng-repeat='item in items'>
<span>{{item.title}}</span>
<input ng-model='item.quantity' >
<span> {{item.price}} </span>
<span>{{item.price*item.quantity}}</span>
<button ng-click="remove($index)">Remove</button>
</div>

<script type="text/javascript">
angular.module("HelloApp", []).controller("CartController", function($scope){
$scope.items=[
{ title: 'paint pots', quantity: 8, price:3.95 },
{ title: 'polka dots', quantity: 17, price: 12.95},
{ title: 'Pebbles', quantity: 5, price: 6.95}
];

$scope.remove = function(index){
$scope.items.splice(index,1);
}

});




</script>
</body>
</html>

原文地址:https://www.cnblogs.com/facial/p/4524847.html