0

ユーザーがユーザー名とパスワードを入力し、コントローラーがAPIを呼び出してそれらが正しいかどうかを確認する、AngularJSを使用してhtmlページを作成しようとしています。これは機能しないコントローラーコードです。私たちを手伝ってくれますか?

'use strict';

angular.module('SiteApp', [])
.controller('LoginCtrl', ['$scope', '$location', '$http', function ($scope, $http) {
  return{
    $scope.user = {username: '', password: ''};

    $scope.go = function() {
        //$scope.msg = 'clicked '+ $scope.user.username + ' ' + 
        //$scope.user.password;
        //alert("Testar entrada na função de go()");
        console.log($scope);
        $http.jsonp('http.//beta.cloogy.com:6969/api/1.0').
            data= {
              "User": user.username,
              "Password": user.password
            };
        .success(function (data) {
          $scope.$parent.image = data;
          return $location.path('/Index')
        });

        .error(function (data) {
           return $scope.msg="Erro, não foi feita validação correctamente!";
            {{msg}}
        });
    }
  }
}]);
4

1 に答える 1

0

There are a lot of javascript syntax errors in your code. The following code is at the very least syntatically correct. Whether it does what you're trying to accomplish I don't know.

'use strict';

angular.module('SiteApp', [])
.controller('LoginCtrl', ['$scope', '$location', '$http', function ($scope, $location, $http) {
  $scope.user = {username: '', password: ''};

  $scope.go = function() {
    $http.jsonp('http.//beta.cloogy.com:6969/api/1.0', {
        data: {
          User: user.username,
          Password: user.password
        }
      })
      .success(function (data) {
        $scope.$parent.image = data;
        $location.path('/Index');
      })
      .error(function (data) {
        $scope.msg="Erro, não foi feita validação correctamente!";
      });
  }
}]);
于 2013-11-08T13:51:04.830 に答える