【发布时间】:2017-06-03 09:26:42
【问题描述】:
为什么控制器不能在单独的文件中工作?
应用结构:
store.html:
<!DOCTYPE html>
<html lang="en" ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
</head>
<body>
<div ng-controller="userController">
<h1>{{user.firstname}}</h1>
</div>
<script src="/static/app/user/userController.js"></script>
<script src="/static/app/app.js"></script>
</body>
</html>
app.js:
var app = angular.module("myApp",[]);
app.controller("myContoller",["$scope",function ($scope) {
}]);
userController.js
app.controller("userController",["$scope",function ($scope) {
$scope.hello= "john doe";
$scope.user = {
id:1,
firstname:"Wojciech"
}
}]);
【问题讨论】:
-
如果您还没有解决问题,请查看我的答案(已更新)。现在应该可以工作了
标签: angularjs