我想要一个显示用户和密码输入的简单HTML表单,现在表单显示在使用bootstrap的模式框中。我在java方面表现不错,但我的手在javascript和angularjs,bootstraps等方面很紧张。
代码1
$scope.modalShown = false;
var showLoginDialog = function() {
if(!$scope.modalShown){
$scope.modalShown = true;
var modalInstance = $modal.open({
templateUrl : 'templates/login.html',
controller : "LoginCtrl",
backdrop : 'static',
});
modalInstance.result.then(function() {
$scope.modalShown = false;
});
}
};
值传递的其他代码。
码2
.controller('LoginCtrl', [ '$scope', '$state', '$modalInstance' , '$window', 'Auth',
function($scope, $state, $modalInstance, $window, Auth ) {
$scope.credentials = {};
$scope.loginForm = {};
$scope.error = false;
//when the form is submitted
$scope.submit = function() {
$scope.submitted = true;
if (!$scope.loginForm.$invalid) {
$scope.login($scope.credentials);
} else {
$scope.error = true;
return;
}
};
//Performs the login function, by sending a requeora to the server with the Auth service
$scope.login = function(credentials) {
$scope.error = false;
Auth.login(credentials, function(user) {
//success function
$modalInstance.close();
$state.go('home');
}, function(err) {
console.log("error");
$scope.error = true;
});
code1是在angular app的maincontroller中编写的,它触发模态框,用户和密码输入从login.js获取凭据