When executing the code, the google developer tool reported the error The controller with the name 'my-injectorCtrl' is not registered. If I want to use inferential injection, what is wrong with this writing. I'm a newbie and I really can't figure out what I'm doing wrong. I hope you can give me some advice. I'd be very grateful!
<p ng-app>
<p ng-controller="my-injectorCtrl">
<span>{{TestInjector1}}</span>
</p>
</p>
var myInjectorModule = angular.module("MyInjectorModule",[]);
var myInjectorCtrl = function($scope){
$scope.TestInjector1 = "Hello Injector";
}
myInjectorModule.controller("myInjectorCtrl",myInjectorCtrl);
阿神2017-05-15 17:15:07
<p ng-app="myInject">
<p ng-controller="myController">
<span>{{TestInjector1}}</span>
</p>
</p>
var myInject = angular.module("myInject",[]);
myInject.controller("myController", ["$scope", function($scope) {
$scope.TestInjector1= "Hello Injector";
}])
曾经蜡笔没有小新2017-05-15 17:15:07
Just change it to the following
<p ng-app="MyInjectorModule">
<p ng-controller="MyInjectorCtrl">
<span>{{TestInjector1}}</span>
</p>
</p>
var myInjectorModule = angular.module("MyInjectorModule",[]);
var myInjectorCtrl = function($scope){
$scope.TestInjector1 = "Hello Injector";
}
myInjectorModule.controller("MyInjectorCtrl",myInjectorCtrl);