发表于: 2017-04-21 22:07:22

1 1188


今天完成的事情/收获:

总算是完成了7的表单验证和双向绑定

var myApp=angular.module('myApp', []);

myApp.controller('myCtrl',function($scope,$http){

$scope.Uname="";

    $scope.Upwd="";

    $scope.red="";

$scope.getValue=function(){

$http({

method: 'POST',

url: '/carrots-admin-ajax/a/login',

data:"name="+ $scope.Uname+"&pwd="+$scope.Upwd,

headers: { 'Content-Type': 'application/x-www-form-urlencoded' }

}).then(function successCallback(response){

var obj=response.data;

  if (obj.message=="success") {

  location.href="http://localhost/JS-6/welcome.html"

  }

  else{

  $scope.red=response.data.message;

}

/* function errorCallback(response) {

            $scope.red=response.data.message;

             请求失败执行代码

        }*/

})

}

})

看了写页面循环 渲染的东西。

在 ng-repeat 中,使用 d in data,可以遍历数组中的每一个成员,如果成员本身就是一个直接的数据,则可以直接使用 d 来显示,如果成员还是一个对象,可以使用 d.id 的方法,来访问成员的各个成员。当然,如果直接显示 d 对象,将会以 JSON 的方式来显示。

<script>
  $scope.data = [
    {id: 0, name: "Sid"},
    {id: 1, name: "SegmentFault"},
    {id: 2, name: "Github"},
    {id: 3, name: "Gitcafe"},
    {id: 4, name: "Coding.NET"},
  ];</script><body>
  <p ng-repeat="d in data">id: {{d.id}}, name: {{d.name}}</p></body>

明天计划的事情:完善热舞7 开始任务8
遇到的问题:
页面循环 渲染 并不怎么理解 。。后台接口该怎么去加也有点云里雾里 

开始的时候双向绑定和¥http格式老是写错:

var myApp=angular.module('myApp', []);

myApp.controller('myCtrl',function($scope,$http){

$scope.getValue=function(){

$http.post('/carrots-admin-ajax/a/login')

data:({

        name:$scope.int1,

      pwd:$scope.int2

   }).then(function (data){

    var obj=JSON.parse(data)

  if (obj.data.message=="success") {

  location.href="http://localhost/JS-6/welcome.html"

  }

  else{

  $scope.redText=obj.data.message;

  }

})

}

})

后台干脆删了 重写。。才写好的


返回列表 返回列表
评论

    分享到