AngularJs Expression无法正常工作

时间:2016-04-13 17:49:24

标签: angularjs

我对# Create a figure instance fig = plt.figure(1, figsize=(4, 4)) # Create an axes instance ax = fig.add_subplot(111) ax.set_ylim([0, 1.2]) # Create the boxplot bp = ax.boxplot(data_to_plot,widths=(0.5, 0.5)) plt.setp(bp['boxes'], linewidth=1) # Save the figure plt.xticks([1, 2], ['A', 'B'],fontsize=16) plt.yticks(fontsize=16) #fig.savefig('fig1.png', bbox_inches='tight') plt.show() 表达式有一个奇怪的问题,{{json_req}}和{{密码}}表达式运行良好,我可以看到我在live中所做的更改。

但无论我在登录名和密码输入中写了什么,{{pseudo}}表达式都没有发生。

我想这是我的一个基本错误,但我现在有点迷失了这个:/。

感谢您的帮助:)

的login.html

{{json_req}}

LoginCtrl.js

<div class="row">
  Pseudo : {{pseudo}}
</div>
<div class="row">
  Password : {{password}}
</div>
<div class="row">
  json : {{json_req}}
</div>
<div class="row">
  <label class="float-center">
    Pseudo
    <input ng-model="pseudo" type="text" required>
    <span class="form-error">
      Pseudo Missing.
    </span>
  </label>
</div>
<div class="row">
  <label class="float-center">
    Password
    <input ng-model="password" type="password" required>
    <span class="form-error">
        Password Missing.
    </span>
  </label>
</div>

3 个答案:

答案 0 :(得分:1)

这是预期的行为。当你写:

$scope.json_req = {
  pseudo: $scope.pseudo,
  password: $scope.password
};

您为$scope.pseudo$scope.password创建值的“快照”。稍后更改模型时,它们不会更新。

$scope.$watchjson_req更改(不是真正推荐)时,您可以设置pseudo并更新password。或者我建议,在范围内写一个getter函数:

Object.defineProperty($scope, 'json_req', {
  get: function() {
    return {
      pseudo: $scope.pseudo,
      password: $scope.password
    }
  }
});

答案 1 :(得分:0)

试试这个:

angular.module("asdfapp",[]).service("User",function(){}).controller('LoginCtrl', ['$scope', 'User', 
                                        function ($scope, User) {


  $scope.json_req = {
    pseudo: "",
    password: ""
  };

  $scope.LoginUser = function () {
    if ($scope.json_req.pseudo != undefined 
        && $scope.json_req.password != undefined) {
      User.login($scope.json_req).then(function (data) {
        $scope.response = data;
        $scope.json_req = {};
      });
    } else
      console.log("UNDEFINED");
  };
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="asdfapp" ng-controller="LoginCtrl">
<div class="row">
  Pseudo : {{json_req.pseudo}}
</div>
<div class="row">
  Password : {{json_req.password}}
</div>
<div class="row">
  json : {{json_req}}
</div>
<div class="row">
  <label class="float-center">
    Pseudo
    <input ng-model="json_req.pseudo" type="text" required>
    <span class="form-error">
      Pseudo Missing.
    </span>
  </label>
</div>
<div class="row">
  <label class="float-center">
    Password
    <input ng-model="json_req.password" type="password" required>
    <span class="form-error">
        Password Missing.
    </span>
  </label>
</div>
</div>

答案 2 :(得分:0)

好的,我找到了解决方案。并且预计这是我的一个愚蠢的错误xD

我应该写ng-model =“json_req.pseudo”而不是ng-model =“pseudo”来填充json_req对象:/

很抱歉打扰了你们!

由于