这个控制器/ html设置有什么问题?Angularjs让控制器工作
view1.html:
<!doctype html>
<html ng-app="myApp" ng-controller="View1Ctrl">
<head>
<title>Hello AngularJS</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
<script src="view1.js"></script>
</head>
<body>
<div >
<p>The content is {{user.content}}</p>
</div>
</body>
</html>
View1.js:
'use strict';
angular.module('myApp.view1', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/view1', {
templateUrl: 'view1/view1.html',
controller: 'View1Ctrl'
});
}])
.controller('View1Ctrl', [ function GetAuthToken($scope, $http) {
$http.get('http://dev.hypr.com/DevAPI/rest/login', {headers: {'API_KEY':'87d2e2c64d9a941f0520653e51eae4935f6a640256f2f85610d0b281fa26a9dd'}}).
success(function(data) {
$scope.Auth = data;
});
},function GetUsers($scope, $http) {
$http.get('http://dev.hypr.com/DevAPI/rest/uafapp/apps/testorigin/users/5',{headers: {'AUTH_TOKEN': GetAuthToken()}}).
success(function(data) {
$scope.user = data;
});
}]);
它不断给这个错误:
[Mon May 30 2016 13:11:01 GMT-0400 (Eastern Daylight Time)] "GET /view1/view1.js" Error (404): "Not found"
这里的路径结构: Path structure
你在哪里包括view1.js在你的HTML?另外,我不确定这是否会导致问题,但我认为您应该将'ng-app'和'ng-controller'移动到'
'标记,以确保您的所有JavaScript文件都是首先加载的'')。 – forgivenson另请注意,您正在使用非常旧版本的角度 – charlietfl
@forgivenson并不罕见将'ng-app'放在''标签上。允许访问像'