The code for my angular and the directive is this
angular.module('myapp',[])
.controller('MainController',MainController)
.directive('myDirective',MyDirective);
MainController.$inject = ['$scope'];
MyDirective.$inject = ['$scope'];
function MainController($scope){
$scope.name = "John";
$scope.value = 20;
$scope.color = "Blue";
}
function MyDirective($scope){
var ddo = {
restrict : 'AE',
controller: 'MainController',
templateUrl : 'mydirective.html'
}
return ddo;
}
And it shows the error
angular.min.js:122 Error: [$injector:unpr] http://errors.angularjs.org/1.6.0/$injector/unpr?p0=%24scopeProvider%20%3C-%20%24scope%20%3C-%20myDirectiveDirective
Why is that and how to fix this.?
$scopelike that to the directive? The directive have access by default to the scope outside, unless you create an insulated scope for it. This is just wrongMyDirective.$inject = ['$scope'];and changedfunction MyDirective($scope){tofunction MyDirective(){?