发表于: 2017-05-23 00:36:51

3 914


今天完成:

实现了$http的页面跳转。

查看了表单验证的几种方法,还不知道选哪种比较合适,感觉ng-show适用性比较强,明天在学习学习。

首先为input输入框设置ng-module=“name/pwd”使用ng-module可以实现双向绑定,使我们输入的值可以实时更新到模型中,

在js中,

var app = angular.module('indexApp',[]);
app.controller('indexCtrl',function ($scope,$http) {
   $scope.enter=function () {
       $http({
           method:"post",
           url:"a/a/login",
          params:{
               name:$scope.name,
               pwd:$scope.pwd
           }

明确angular方法和控制器,添加好ng-click之后就可以绑定点击函数,

然后设置$http的各项设置,后边的name和pwd字段一定要使用$scope,这样才会实时获取双向绑定的值。

.then(
       function successCallback(reponse) {
           console.log(reponse)
           //.判断接口返回参数是否正确,正确则跳转,错误弹出警示框
           if (reponse.data.code == 0){
               window.location.href="../html/background.html";
           }else {
               alert("错误的帐户名或密码!")
           }

然后使用then方法判断返回的值是否正确,作为跳转的条件,


明天计划:

为input添加表单验证,学习ng-repeat的知识。完成任务7剩余部分


遇到困难:

上边设置$http方法的时候使用的是params的方法,之前使用jq写法的时候使用的data,不知道这两种方法有什么区别?


收获:

学会了使用$http和表单验证。


返回列表 返回列表
评论

    分享到