Reputation: 4608
I am very new to angular js and want to make a very simple website, that does the following: when clicking on a button, it will randomly generate a number, and if the number is odd, redirect to google, otherwise redirect to apple website. I have done the following:
<!doctype html>
<html lang="en" ng-app="homeapp">
<head> ... all imports </head>
<body ng-controller="homeappCtrl">
<a href="{{urlToPick}}">Click</a>
</body>
</html>
and then in the controller.js, I have:
var homeapp= angular.module('homeappController', []);
homeappController.controller('homeappCtrl', ['$scope',
function($scope) {
if (Math.floor((Math.random() * 10) + 1)%2==0)
{$scope.urlToPick = 'http://google.ca';}
else
{$scope.urlToPick = 'http://apple.com';}
}]);
The problem is that when I click on the link, the urlToPick is not resolved and therefore the link returns error. (the link url is something like xxx/{{urlToPick}} )
I guess I have done something wrong but please tell me where... Thanks!
Upvotes: 0
Views: 168
Reputation: 2596
Your ng-app
and your angular.module
definitions are different.
Change
var homeapp= angular.module('homeappController', []);
to
var homeapp= angular.module('homeapp', []);
Upvotes: 1