2 回答
TA贡献1856条经验 获得超5个赞
我认为根据您的代码,您应该获取三个文件 1. 在 module.js 文件中声明角度模块
var app = angular.module("myApp", []);添加第一个控制器 appController.js
app.controller("appController",["$scope", function($scope){
$scope.myAppText = "你好,我是 appController text";
}]);
添加第二个控制器文件 secondController.js
app.controller("secondController",["$scope", function($scope){ $scope.secondControllerText = "你好,我是 seasdfsdfasdfacond 控制器文本"; }]);
现在把它们放在这个层次结构中 - 添加 Angular JS 的 ref 然后 1 module.js 2 appController.js 3secondController.js
TA贡献1712条经验 获得超3个赞
首先,我想澄清一下这是不正确的:
<div ng-controller="appController">
<p>App text : {{myAppText}}</p>
<p>secondControllerModule: {{ secondControllerText }}</p>// Defined in the wrong ng-controller,
so move it to the correct one.
</div>
您收到该错误的原因是您在 js 文件中定义了两次应用程序模块。这很简单,你需要做的就是在你的secondModule.js 中去掉第二个参数
angular.module("myApp")// Needs to be like this
.controller("secondController",["$scope", function($scope){
$scope.secondControllerText = "Hello, I am seasdfsdfasdfacond Controller Text"
}])
然后在你的app.js 文件中
angular.module("myApp", [])
.controller("appController",["$scope", function($scope){
$scope.myAppText = "Hello, I am appController text"
}])
然后在您的 HTML 文件中,您需要修复脚本的顺序
<script src="./angular.js"></script>
<script src="./app.js"></script> // App module must be first because the module is defined here
<script src="./secondModule.js"></script>
添加回答
举报
