AngularJS很基础的记录

来源:互联网 发布:js 滚动延迟加载 编辑:程序博客网 时间:2024/05/01 22:59

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);
0 0