I am trying to learn Angular.js, I am using ng-boiler-plate to manage my test application.
However I have ran into a ptoblem and can't see the reason for it not working. Basically I am trying to inject a Factory and then call it from a directives controller.
However when I try to call it I get an error reporting the factory name (in this case dashboardFac) is undefined.
I will include the directive and factory below:
Directive:
angular.module( 'locationSelector', [
'ngBoilerplate.locationFactory'
] )
.directive( 'locationSelector', function() {
return {
restrict: 'A',
//template: '<h3>asdfasdfasd</h3>',
templateUrl : 'components/locationSelector/locationSelector.tpl.html',
link: function( scope, element, attrs ) {
console.log("link working ");
var $input = angular.element( document.querySelector( '#location' ) );
$input.bind('focus', function() {
console.log("stay focused son");
});
},
controller: function($scope, dashboardFac, $element){
$scope.locyTexy = "";
$scope.api = dashboardFac;
console.log($scope.api);
$scope.change = function() {
console.log("asdfasd");
dashboardFac.assets.getLocations().then(function(result){
});
};
}
};
})
;
Factory:
angular.module( 'ngBoilerplate.locationFactory', [
]).factory('dashboardFac', function($http, $q){
this.assets = {
getLocations: function(args) {
var deferred = $q.defer();
var parmUrl = "will be some url eventually";
$http.jsonp({
method: 'GET',
url: parmUrl
}).
success(function(data, status) {
deferred.resolve(data);
}).
error(function(data, status) {
deferred.reject(data);
});
return deferred.promise;
}
};
});
Any help would be greatly apprieacted, I have a feeling I am missing something fundamental but hopefully someone can help point me in the right direction.
Thanks in advance.