请大神解答
angularjs吧
全部回复
仅看楼主
level 2
<!DOCTYPE html>
<html ng-app='myApp'>
<head>
<meta charset="utf-8" />
<title>Your Shopping Cart</title>
</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|currency}}</span>
<span>{{item.price*item.quantity|currency}}</span>
<button ng-click='remove($index)'>Remove</button>
</div>
<script src="js/angular.js"></script>
<script>
function cartController($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>
为什么会这样?
2015年10月14日 03点10分 1
level 2
<script>
function cartController($scope)
这两句中间加点代码
angular.module("myApp")
.controller("cartController", cartController);
2015年10月14日 03点10分 2
不行啊,大神
2015年10月14日 03点10分
function cartController($scope) 再改下 cartController =function ($scope)
2015年10月14日 03点10分
@没有躺着 这个没关系的吧。
2015年10月14日 03点10分
cartController这个函数.controller("cartController", 【cartController】);换到后面那里去
2015年10月14日 03点10分
level 2
<!DOCTYPE html>
<html>
<script src= "angular.js"></script>
<body ng-app="myApp">
<div 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|currency}}</span>
<span>{{item.price*item.quantity|currency}}</span>
<button ng-click='remove($index)'>Remove</button>
</div>
</div>
<script>
(function() {
angular.module('myApp', [])
.controller("cartController", cartController);
function cartController($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>
這個我檢查過的,可以了
2015年10月14日 04点10分 4
<script src= "angular.js"></script>這我換過,你換回來
2015年10月14日 04点10分
1