gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 18:06:28 25 4
gpt4 key购买 nike

我是 AngularJS 的新手,2天前开始使用,但我无法解决这个问题。

The JS Console Error here

看来我的指令 ng-controller 找不到我的 Controller 。

这是我的代码:

<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>

(这是主页的一部分,我用 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>

希望有人能帮助我,谢谢! :D

最佳答案

一个 html 中不能有两个 ng-app 指令。删除内部 Controller 并将该 Controller 添加到第一个 ng-app

关于javascript - AngularJS - 找不到我的 ng-controller 的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42459814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com