学习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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值