I keep encountering an error in AngularJS saying that the service is not defined, even though my controller and module are properly connected:
application.js:
var myapp=angular.module('myApp', []);
myapp.service('productService', function() {
var productList = "";
var addProduct = function(newObj) {
productList=newObj;
};
var getProducts = function(){
return productList;
};
return {
addProduct: addProduct,
getProducts: getProducts
};
});
controller1.js:
myapp.controller('contrl1', ['$scope','productService', function ($scope) {
var st="datsat";
productService.addProduct(st);
}]);
Controller 2:
myapp.controller('contrl2', ['$scope','productService', function ($scope) {
$scope.products = productService.getProducts();
}]);
Furthermore, I have included links to the controller.js file and application.js file in the views.