114
rated 0 times
[
119]
[
5]
/ answers: 1 / hits: 18082
/ 11 Years ago, fri, october 25, 2013, 12:00:00
I'm new to AngularJS. I'm trying to run a simple example from a book, but it's not working correctly, and I can't figure out why.
This code runs fine:
<html ng-app>
<head>
<script src=angular.js></script>
<meta charset=UTF-8>
<title>Angular </title>
</head>
<body>
<div ng-controller=HelloController>
<input ng-model=greeting.text/>
<p>{{greeting.text}}, World!</p>
</div>
<script src=angular.js></script>
<script>
function HelloController($scope) {
$scope.greeting = {text: 'Hello'};
}
</script>
</body>
</html>
But this is the code I'm having problems with
<html ng-app='myApp'>
<head>
<title>Shopping Cart</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| currency}}</span>
<span>{{item.price * item.quantity| currency}}</span>
<button ng-click=remove($index)>Remove</button>
</div>
<script src=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>
Expecting this output:
But getting this output:
I don't understand why I'm not getting the data output, and why it's not repeating. Basically, why the example is not running. I copy and paste the code straight from the book.
More From » angularjs