I am facing difficulties with communication between my application and a module that I have developed. Below is the AngularJS module that I created.
(function (document, window) {
'use strict';
var piCart = angular.module('piCart', []);
piCart.config(['$routeProvider', function($routeProvider){
$routeProvider.
when('/cart', {
templateUrl: "packages/pi-cart/segments/cart.html",
controller: 'CartController',
private : true
}).
when('/checkout', {
template: "Checkout Page",
// controller: 'CartController',
private : true
});
}]);
piCart.factory('TestFactory', function(){
return{
test : function(){
return 'test works';
}
}
});
piCart.controller("CartController",function(TestFactory){
console.log("Cart Controller Running");
console.log(TestFactory.test());
});
})(document, window);
This module is loaded into my main application like this:
var app = angular.module('app', ['ngRoute', "ui.bootstrap", "googlechart", "piCart"]);
I am attempting to access the TestFactory module from the app.controller in the following way:
app.controller('ProductController',function($scope){
$scope.addToCart = function(id){
//alert("clicked: "+id);
test = TestFactory.test();
console.log(test);
};
});
However, I encounter the error message:
ReferenceError: TestFactory is not defined