Angularjs选择设置为第一项的选项不起作用

时间:2016-05-16 09:48:37

标签: javascript angularjs

我正在使用角度和语义ui。我试图通过选择选项选择Y和N.基本上我只想在页面显示时选择第一个项目。试过很多方法,但我无法使它发挥作用。

请看看这个傻瓜。

angular.module('myapp', [])

.controller('testctrl', function ($scope){
  $scope.add = {};
  $scope.Consigns = [{value: 'N',label: 'N'}, {value: 'Y',label: 'Y'}];
  $scope.add.consign = $scope.Consigns[0].label;
})

.controller('testctrl1', function ($scope){
  $scope.add = {};
  $scope.Consigns1 = [{value: 'N',label: 'N'}, {value: 'Y',label: 'Y'}];
  $scope.add.consign1 = $scope.Consigns1[0].label;
});

https://plnkr.co/edit/cHcLd14xKFxLMS4uy0BM?p=preview

3 个答案:

答案 0 :(得分:1)

在默认占位符中打印模型值。而不是在label中发送$scope.add.consign值,您可以发送整个对象并打印所需的内容。

工作人员:https://plnkr.co/edit/XeuiS7p3K1OOx5nHL9c5?p=preview

答案 1 :(得分:0)

javascript:

V[ITM[as.logical(max.col(cbind(CV, ExV))-1)], t] =  
SimFieldValue[ITM[as.logical(max.col(cbind(CV,ExV))-1)],t+1]

V[,t] <- ifelse(V[,t]==0,V[,t+1]*exp(-r),V[,t])

HTML:

 $scope.ListOrder =
        [
            { Name: "price", Id: 1 },
            { Name: "exist", Id: 2 },
            { Name: "Sale", Id: 3 },
            { Name: "New", Id: 4 }
        ];
 $scope.Order = { Name: "exist", Id: 1 };

答案 2 :(得分:0)

删除

 <script>
   $('.ui.dropdown').dropdown();
</script>

并将select标签更改为此

 <select ng-model="add.consign" class="ui fluid dropdown" ng-options="x.label as x.label for x in Consigns">
          <option value=""></option>
 </select>