Angularjs 意外的绑定行为
我有选择列表,我设置了要选择的默认选项。发生的事情是几秒钟它工作,然后它消失,列表中的空白选项被选择为默认。< /P>Angularjs 意外的绑定行为,angularjs,Angularjs,我有选择列表,我设置了要选择的默认选项。发生的事情是几秒钟它工作,然后它消失,列表中的空白选项被选择为默认。< /P> <div class="form-group"> <select class="form-control" ng-model="item.action" ng-options="option.value as option.title for option in options"> </se
<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>
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请求中发送它你能创建一个plunker吗。。上面的代码似乎很好。您以后是否有机会更改选项?让我粘贴控制器代码的其余部分。请尝试在ng选项中添加“按选项跟踪”。值或将item.action设置为$scope。选项[0]与您的代码完美配合
$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);
}
);