對不起,有一大段代碼,但我的AngularJS模塊出現問題,按照these lessons創建。我想我的角模塊與ASP.NET MVC一起工作,但我甚至不能運行它。
(function() {
var AAngScript = angular.module('AAngScript', ['ngRoute']);
AAngScript.controller('LoginController', ['$scope', '$routeParams', '$location', 'LoginFactory', function ($scope,
$routeParams, $location, LoginFactory) {
$scope.loginForm = {
emailAdress: '',
password: '',
rememberMe: false,
returnUrl: $routeParams.returnUrl,
loginFailure: false
};
$scope.login = function() {
var result = LoginFactory($scope.loginForm.emailAdress, $scope.loginForm.password, $scope.loginForm.rememberMe);
result.then(function (result) {
if (result.success) {
if ($scope.loginForm.returnUrl !== undefined) {
$location.path('/productcategory');
} else {
$location.path($scope.loginForm.returnUrl);
}
} else {
$scope.loginForm.loginFailure = true;
}
});
}
}]);
AAngScript.controller('RegisterController', ['$scope', '$location', 'RegistrationFactory', function ($scope, $location, RegistrationFactory) {
$scope.registerForm = {
emailAdress: '',
password: '',
confirmPassword: '',
registrationFailure: false
};
$scope.register = function() {
var result = RegistrationFactory($scope.registerForm.emailAdress, $scope.registerForm.password, $scope.registerForm.confirmPassword);
result.then(function (result) {
if (result.success) {
$location.path('/routeOne');
} else {
$scope.registerForm.registrationFailure = true;
}
});
}
}]);
AAngScript.factory('AuthHttpResponseInterceptor', ['$q', '$location', function ($q, $location) {
return {
response: function (response) {
if (response.status === 401) {
console.log("Response 401");
}
return response || $q.when(response);
},
responseError: function (rejection) {
if (rejection.status === 401) {
console.log("Response Error 401", rejection);
$location.path('/login').search('retutnUrl', $location.path());
}
return $q.reject(rejection);
}
}
}]);
AAngScript.factory('LoginFactory', ['$http', '$q', function ($http, $q) {
return function (emailAdress, password, rememberMe) {
var deferredObject = $q.defer();
$http.post(
'/Account/Login', {
Email: emailAdress,
Password: password,
RememberMe: rememberMe
}
).
success(function (data) {
if (data == "True") {
deferredObject.resolve({ success: true })
} else {
deferredObject.resolve({ success: false })
}
}).
error(function() {
deferredObject.resolve({ success: false })
});
return deferredObject.promise;
}
}]);
AAngScript.factory('RegistrationFactory', ['$http', '$q', function ($http, $q) {
return function (emailAdress, password, confirmPassword) {
var deferredObject = $q.defer();
$http.post(
'/Account/Register', {
Email: emailAdress,
Password: password,
ConfirmPassword: confirmPassword
}
).
success(function (data) {
if (data == "True") {
deferredObject.resolve({ success: true });
} else {
deferredObject.resolve({ success: false });
}
}).
error(function() {
deferredObject.resolve({ success: false });
});
return deferredObject.promise;
}
}]);
AAngScript.config('appConfig', ['$routeProvider', '$httpProvider', function ($routeProvider, $httpProvider) {
$routeProvider.
when('/register', {
templateUrl: 'Account/Register',
controller: 'RegisterController'
})
.when('/login', {
templateUrl: '/Account/Login.html',
controller: 'LoginController'
});
$httpProvider.interceptors.push('AuthHttpResponseInterceptor');
}]);
}());
總有一個錯誤[$injector:modulerr]
,我真的不知道該怎麼辦。 「請求」對角模塊位於局部視圖_Layout
這些代碼:
<html ng-app="AAngScript">
<head></head>
<body>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<script src="~/Scripts/angular.min.js"></script>
<script src="~/Scripts/angular-route.min.js"></script>
<script src="~/Scripts/AAngScript.js"></script>
....
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>
感謝您幫助我!
你可以添加使用'[$注射器:modulerr]整個錯誤消息'? –
既然你沒有發佈它,你能確保ngRoute實際上包含在你的索引中嗎? –