angularjs - Access a service from inside a directive's compile -
i having hard time access service inside directive. define service via $http , $q, , inject directive. can;t directive access service.
service.js
'use strict'; var app = angular.module('app.services', []); app.factory('classification', function($http,$q) { return { query: function getall() { var deferred = $q.defer(); $http.get('index.php/classifications').then(function(classi) { deferred.resolve(classi.data); }, function getwebsiteserror(reason) { deferred.reject(reason); }); return deferred.promise; } }; });
app.js
'use strict'; /* app module */ var app = angular.module('app', ['app.controllers', 'app.services', 'app.directives', 'ui']); app.config(['$routeprovider', function($routeprovider) { $routeprovider. when('/', {templateurl: 'partials/welcome.html'}). when('/websites/:websiteid', {templateurl: 'partials/website/details.html', controller: 'websitedetailsctrl'}). otherwise({redirectto: '/'}); }]);
and directive.js :
'use strict'; var app = angular.module('app.directives', ['app.services']); app.directive("regionselect",['classification', '$compile', function($compile, classification){ classification.query();<-- throw exception : has no method query() return{ restrict : "e", templateurl : "/js/directives/locationselect3.html", transclude: true, compile: function (telement, tattr, transclude){ var loaded = false; } }; }]);
any idea doing wrong?
could ordering?
app.directive("regionselect",['classification', '$compile', function($compile, classification){
you declare
['classification', '$compile',
but the function says
function($compile, classification){
which backwards.
Comments
Post a Comment