I am having a js file like below.
(function(){
angular.module("MyModule",[])
.service('testService',testService)
.directive("testDirective",testDirective);;
function testDirective(testService){
var directive = {
template: '<input type="text">',
restrict: 'EA'
};
return directive;
}
function testService($scope){
$scope.name = "testName";
}
}())
When I load the page I am getting an error like below.
Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope <- inputResourceService <- inputResourceDirective
Please help me with the issue.
$scope
dependency will never be available inside service function
You should create an variable inside your service that will be easily shareable among-st your all angular component
(function(){
angular.module("MyModule",[])
.service('testService',testService)
.directive("testDirective",testDirective);;
function testDirective(testService){
var directive = {
template: '<input type="text" ng-model="something">',
restrict: 'EA',
link: function(scope, element, attrs){
scope.name = testService.name; //assigned service variable value to scope
}
};
return directive;
}
function testService(){
var testService = {}
testService.name = "testName";
return testService;
}
}())
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments