意外的绑定行为

时间:2015-05-07 17:48:33

标签: angularjs

我有选择列表我设置了默认选项。发生的事情是它只有几秒钟工作然后消失,列表中的空白选项被选为默认值。

 <div class="form-group">
              <select class="form-control" ng-model="item.action" ng-options="option.value as option.title for option in options">
              </select>
            </div>

我想设置defualt选项: 所以我的控制器看起来像这样:

$scope.item = {};
  $scope.options = [{
    title: 'On entering',
    value: 'enter'
  }, {
    title: 'On exiting',
    value: 'exit'
  }];
  $scope.item.action= $scope.options[0].value;

  $scope.profile = me.getUser();
  $scope.profile.then(
    function(user) {
      $scope.owner = user;
      $scope.item = {};
      $scope.item.data = '';
      $scope.item.published = true;
      $scope.item.action= $scope.action;
      $scope.item.owner = $scope.owner.displayName;
    },
    function(response) {
      console.log(response);
    }
  );

me是一种用于处理用户数据的服务。 我再次定义$scope.item = {};的原因是因为我无法将displayName添加到范围之外的$scope.item。 我评论了这部分代码并且效果很好:

  $scope.profile = me.getUser();
  $scope.profile.then(
    function(user) {
      $scope.owner = user;
      $scope.item = {};
      $scope.item.data = '';
      $scope.item.published = true;
      $scope.item.action= $scope.action;
      $scope.item.owner = $scope.owner.displayName;
    },
    function(response) {
      console.log(response);
    }
  );

但现在我无法弄清楚如何构建我的item对象以在HTTP请求中发送它

0 个答案:

没有答案
相关问题