AngularJS很基础的记录

1. ng-model 指令可以为应用数据提供状态值(invalid, dirty, touched, error):

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script> 
</head>
<body>
<form ng-app="" name="myForm" ng-init="myText = 'test@runoob.com'">
Email:
<input type="email" name="myAddress" ng-model="myText" required>
<p>编辑邮箱地址,查看状态的改变。</p>
<h1>状态</h1>
<p>Valid: {{myForm.myAddress.$valid}} (如果输入的值是合法的则为 true)。</p>
<p>Dirty: {{myForm.myAddress.$dirty}} (如果值改变则为 true)。</p>
<p>Touched: {{myForm.myAddress.$touched}} (如果通过触屏点击则为 true)。</p>
<p> <span ng-show="myForm.myAddress.$error.email">不是一个合法的邮箱地址</span></p>
</form>
</body>
</html>

2.post

var app = angular.module("registApp", []);
app.controller("resgistCtrl", function ($scope, $http, $timeout, $window) {
   $scope.formSub = function () {
       $http({
           method: 'POST',
           url: '${request.getContextPath()}/user/login',
           data: "email=" + $scope.email + "&password=" + $scope.password,
           headers: {'Content-Type': 'application/x-www-form-urlencoded'}
       })
               .success(function (data) {
                   console.log(data);
                   if (data.status == 200) {
                       $scope.msg = "登录成功,跳转到主页";
                   } else {
                       $scope.msg = "用户名或密码出错";
                   }
               });
   }
});

3.延迟跳转

$timeout(function () {
            $window.location.href = '${request.getContextPath()}/main';
           }, 1000);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值