I've working on refactoring my Controllers, Factories and Directives to the recommended Angular-Style-Guide for Angular Snippets.
I've gotten the Controllers and Factories working correctly with the new style, but not the Directives.
Unknown provider: $scopeProvider <- $scope <- platformHeaderDirective
The new Directive style with errors:
(function() { "use strict";
angular
.module('platformHeaderDirectives', [])
.directive('platformHeader', directive);
directive.$inject = ['$scope'];
/* @ngInject */
function directive ($scope) {
var directive = {
templateUrl : "header/platform_header/platformHeader.html",
restrict : "E",
replace : true,
bindToController: true,
controller: Controller,
controllerAs: 'vm',
link: link,
scope: {
}
};
return directive;
function link(scope, element, attrs) {
}
}
/* @ngInject */
function Controller () {
}
})();
My old working Directive that does not throw errors:
(function() { "use strict";
angular.module('platformHeaderDirectives', [])
.directive('platformHeader', function() {
return {
templateUrl : "header/platform_header/platformHeader.html",
restrict : "E",
replace : true,
scope : false,
controller : ['$scope',
function($scope) {
/** Init platformHeader scope */
// var vs = $scope;
}]
}
});
})();
$scope
can not be injected to directive. i have changed code to inject $scope
in controller of directive.
Code:
(function() { "use strict";
angular
.module('platformHeaderDirectives', [])
.directive('platformHeader', directive);
/* @ngInject */
function directive () {
var directive = {
templateUrl : "header/platform_header/platformHeader.html",
restrict : "E",
replace : true,
bindToController: true,
controller: Controller,
controllerAs: 'vm',
link: link,
scope: {
}
};
return directive;
function link(scope, element, attrs) {
}
}
/* @ngInject */
Controller.$inject = ['$scope'];
function Controller ($scope) {
}
})();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With