suchen

Heim  >  Fragen und Antworten  >  Hauptteil

angular.js - 关于报The controller with the name '' is not registered的问题

    执行代码的时候,google developer tool报The controller with the name 'my-injectorCtrl' is not registered的错误,如果我想使用推断式注入,这样写哪里错了。本人菜鸟,实在想不出哪里错了,望各位大神指点,感激不尽!

HTML文件的内容:

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

JS文件的内容:

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

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

myInjectorModule.controller("myInjectorCtrl",myInjectorCtrl);
巴扎黑巴扎黑2776 Tage vor2124

Antworte allen(2)Ich werde antworten

  • 阿神

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

    Antwort
    0
  • 曾经蜡笔没有小新

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

    改成下面这样就可以了

    HTML文件内容:

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

    JS文件内容:

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

    Antwort
    0
  • StornierenAntwort