因为某种原因,我的管理员似乎没有注册,我真的不知道为什么.
我一直在学习AngularJS和Django在PluralSight上的开发过程。教官和我之间唯一的区别是,我用的是角1.6.4,他用的是1.5.0。我以前遇到过一些错误(比如路由语法),但总体来说还不错。
编辑:
我应该提到的是,我只是按照老师的指示写了和他一样的代码。
但是现在,我只是被困住了。我在scrumboard.config.js中找到了这个路由
(function () {
"use strict";
angular.module('scrumboard.demo', ["ngRoute"])
.config(["$routeProvider", config])
.run(["$http", run]);
function config($routeProvider) {
$routeProvider
.when('/', {
templateUrl: "/static/html/scrumboard.html",
controller: "ScrumboardController",
})
.when('/login', {
templateUrl: "/static/html/login.html",
controller: "LoginController",
})
.otherwise('/');
}
function run($http) {
$http.defaults.xsrfHeaderName = 'X-CSRFToken';
$http.defaults.xsrfCookieName = 'csrftoken';
}
})();该控制器用于login.html
(function() {
"use strict";
angular.module("scrumboard.demo", [])
.controller("LoginController",
["$scope", "$http", "$location", LoginController]);
function LoginController($scope, $http, $location) {
$scope.login = function () {
$http.post('/auth_api/login/', $scope.user)
.then(function (response){
$location.url("/");
},
function(error) {
//failure
$scope.login_error = "Invalid username or password";
});
};
};
})();当导航到localhost:8000/#!/login时,我可以看到我的表单:
<form ng-submit="login()">
<div style="...">{{ login_error }}</div>
<div>
<label>Username</label>
<input type="text" ng-model="user.username"/>
</div>
<div>
<label>Password</label>
<input type="password" ng-model="user.password"/>
</div>
<div>
<button type="submit">Submit</button>
</div>
</form>但出于某种奇怪的原因,我的控制台一直告诉我,我的LoginController没有注册。
有人能帮我朝正确的方向走吗?
对不起,如果我错过了任何类型的文件,但我是非常新的角,所以我真的不知道要添加什么。
如果您需要更多的信息,请告诉我!
发布于 2017-05-14 14:47:01
从控制器对[]的定义中删除login.html。
angular.module("scrumboard.demo")
.controller("LoginController",
["$scope", "$http", "$location", LoginController]);发布于 2017-05-14 14:47:38
您将声明模块scrumboard.demo两次。
删除[]中的
angular.module("scrumboard.demo")
.controller("LoginController",
["$scope", "$http", "$location", LoginController]);如果没有angular.module()的第二个参数,它就是一个getter,否则它就是一个setter。
发布于 2017-05-14 14:58:19
在入口点html中,文件scrumboard.config.js的脚本标记应该位于文件控制器文件的前面。同样,正如@charlietfl所说,应该删除两次声明。
像这样,
<script src="your_path/scrumboard.config.js"></script>
<script src="your_path/scrumboard.controller.js"></script>希望这能纠正这个问题。
https://stackoverflow.com/questions/43965175
复制相似问题