I recently ventured into the world of AngularJS and started by creating a module without any services or factories. Everything was running smoothly until I decided to introduce services and factories into my code. Suddenly, things stopped working.
Here is the initial declaration that is now causing issues:
angular.module('root',[])
.controller("index",["$scope",function ($scope){
$scope.message="My name";
$scope.favouriteWord;
$scope.favouriteColor;
$scope.favouriteShape;
$scope.value = 1;
$scope.isBold = function() {
return ($scope.value % 2===0);
}
$scope.isUnderlined = function() {
return ($scope.value % 5===0);
}
$scope.products=[
{id: 1, name:"House Jockey"},
{id: 2, name:"Golf club"},
{id: 3, name:"Baseball Bat"},
{id: 4, name:"Lacrosse stick"}];
$scope.favsha = true;
$scope.factor = 6;
$scope.product = $scope.factor * 2;
}]);
The factory added:
angular.module('root',["services"])
.controller("index",["$scope","square",function ($scope,square){
$scope.product=square;
}]);
The service added:
angular.module('root',["services"])
.controller("index",["$scope","message",function ($scope,message){
$scope.message=message;
}]);