search

Home  >  Q&A  >  body text

angular.js - Regarding the problem of reporting The controller with the name '' is not registered

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!

Content of HTML file:

<p ng-app>
    <p ng-controller="my-injectorCtrl">
        <span>{{TestInjector1}}</span>
    </p>
</p>

Contents of JS file:

var myInjectorModule = angular.module("MyInjectorModule",[]);

var myInjectorCtrl = function($scope){
    $scope.TestInjector1 = "Hello  Injector";
}

myInjectorModule.controller("myInjectorCtrl",myInjectorCtrl);
巴扎黑巴扎黑2775 days ago2114

reply all(2)I'll reply

  • 阿神

    阿神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";
    }])

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-15 17:15:07

    Just change it to the following

    HTML file content:

    <p ng-app="MyInjectorModule">
        <p ng-controller="MyInjectorCtrl">
            <span>{{TestInjector1}}</span>
        </p>
    </p>

    JS file content:

    var myInjectorModule = angular.module("MyInjectorModule",[]);
    var myInjectorCtrl = function($scope){
        $scope.TestInjector1 = "Hello  Injector";
    }
    myInjectorModule.controller("MyInjectorCtrl",myInjectorCtrl);

    reply
    0
  • Cancelreply