gpt4 book ai didi

javascript - 将 Controller 添加到 ngRoute 时出现意外标识符

转载 作者:太空狗 更新时间:2023-10-29 13:50:13 25 4
gpt4 key购买 nike

我遇到过这样的问题,当我将 Controller 添加到我的路由代码时,它无法识别意外的标识符。不知道为什么会这样这是我的路线提供者:

    app.config(function($routeProvider) {
$routeProvider
.when("/login", {
title: 'Login',
templateUrl: 'assets/login.html'
controller: authCtrl
})
});

这是我的 Controller :

    app.controller('authCtrl', function ($scope, $rootScope, $routeParams, $location, $http, Data) {
//initially set those objects to null to avoid undefined error
$scope.login = {};
$scope.signup = {};
$scope.doLogin = function (customer) {
Data.post('login', {
customer: customer
}).then(function (results) {
Data.toast(results);
if (results.status == "success") {
$location.path('dashboard');
}
});
};
$scope.signup = {email:'',password:'',name:'',phone:'',address:''};
$scope.signUp = function (customer) {
Data.post('signUp', {
customer: customer
}).then(function (results) {
Data.toast(results);
if (results.status == "success") {
$location.path('dashboard');
}
});
};
$scope.logout = function () {
Data.get('logout').then(function (results) {
Data.toast(results);
$location.path('login');
});
}
});

我在我的 html 中包含了这样的路径:

   <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"/>
<script src="app/angular-route.min.js"></script>
<script src="app/angular-animate.min.js" ></script>
<script src="app/toaster.js"></script>
<script src="app/app.js"></script>

最佳答案

您的代码中有一些拼写错误:

 app.config(function($routeProvider) {
$routeProvider
.when("/login", {
title: 'Login',
templateUrl: 'assets/login.html', // <---- missing ','
controller: 'authCtrl' // <----- should be format to string
})
});

不知道能不能解决你的问题

关于javascript - 将 Controller 添加到 ngRoute 时出现意外标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39161536/

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