简体   繁体   English

AngularJS-找不到我的ng-controller的名称

[英]AngularJS - Name of my ng-controller can't be found

I'm new at AngularJS, started 2 days ago, but I can't resolve this problem. 我是2天前开始的AngularJS的新手,但我无法解决此问题。

The JS Console Error here JS控制台错误在这里

It seems that my directive ng-controller can't find my controller. 看来我的指令ng-controller找不到我的控制器。

Here is my code : 这是我的代码:

 <section class="index" ng-app="indexApp" ng-controller="cRegister"> <form> <input type="text" ng-model="username" /> <input type="password" ng-model="password" /> <input type="submit" ng-click="" /> </form> <script> var app = angular.module('indexApp', []) app.controller('cRegister', ['$scope', function() { console.log('controller: true'); }]); </script> </section> 

(This is a part of the main page, that I displayed with ng-view) : (这是我用ng-view显示的主页的一部分):

 <html ng-app="web"> <head> <title>AngularJS, tries</title> <meta charset="utf-8"> </head> <body> <div ng-view></div> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.min.js"></script> <script src="https://code.angularjs.org/1.6.2/angular-route.min.js"></script> <script> var app = angular.module('web', ['ngRoute']); app.config(function($routeProvider) { $routeProvider .when('/', { templateUrl: 'partials/index.php' }) .otherwise({ redirectTo: '/' }) }); </script> </body> </html> 

Hope someone could help me, thank you ! 希望有人能帮助我,谢谢! :D :D

you cannot have two ng-app directive in one html. 您不能在一个html中包含两个ng-app指令。 remove the inner one and add that controller to the first ng-app 删除内部控制器并将该控制器添加到第一个ng-app

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM