I recently discovered angularJS and have been trying to learn it, so I copied the simple todo tutorial into a yeoman generator angular app which happened to work just fine. However when I tried to write my own version, I cannot get the data to update automatically.
My HTML:
<div class="hero-unit">
<ul>
<li ng-repeat="p in phones">{{p.name}} - {{p.snippet}}</li>
</ul>
<a href="#" ng-click="addPhone()">click me</a>
</div>
My main.js
'use strict';
angular.module('ngApp') .controller("MainCtrl", function ($scope) {
$scope.phones = [
{name: "Nexus S",
snippet: "Fast just got faster with Nexus S."},
{name: "Motorola XOOM™ with Wi-Fi",
snippet: "The Next, Next Generation tablet."},
{name: "MOTOROLA XOOM™",
snippet: "The Next, Next Generation tablet."}
];
$scope.addPhone = function()
{
console.log('clicked');
$scope.phones.push({
name: "iPhone 5",
snippet: "Awesome phone man"
});
};
});
I have not modified my app.js yet but here it is just in case:
'use strict';
angular.module('ngApp', [])
.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.otherwise({
redirectTo: '/'
});
});
What am I doing wrong? Please help before I lose my mind. I'm sure it's something extremely simple that I am over looking. However when I click the link the item does not add itself to the list. However on initial load the list loads just fine.