Javascript 使用angularjs选择框中的选定选项

Javascript 使用angularjs选择框中的选定选项,javascript,codeigniter,angularjs,angularjs-directive,angularjs-scope,Javascript,Codeigniter,Angularjs,Angularjs Directive,Angularjs Scope,我使用Codeigniter和AngularJs开发了一个应用程序。我想在手动选择框中设置默认项,但angular添加了一个空的未定义项 <select class="form-control" ng-model="newItem.is_active"> <option value="N" ng-selected="selected"><?php echo $this->lang->line('label_inactive'); ?><

我使用
Codeigniter
AngularJs
开发了一个应用程序。我想在手动选择框中设置默认项,但angular添加了一个空的未定义项

<select class="form-control" ng-model="newItem.is_active">
   <option value="N" ng-selected="selected"><?php echo $this->lang->line('label_inactive'); ?></option>
   <option value="Y"><?php echo $this->lang->line('label_active'); ?></option>
</select>

来自文档

如果表达式是truthy,那么将在元素上设置特殊属性“selected”

所以你可以做一些像

<option value="Y"  ng-selected="newItem.is_active=='Y'"><?php echo $this->lang->line('label_active'); ?></option>

在控制器中,您可以设置
选定的
值,如

$scope.selected = true; //put your selected condition


账单
产品:  


数量:

价格:    成本:{{quantity*selectedName.price}}/-

SGST(6%):{{quantity*selectedName.price*6/100}/-

CGST(6%):{{quantity*selectedName.price*6/100}/-

商品及服务税合计:{{数量*selectedName.price+数量*selectedName.price*12/100}/-

折扣:{((数量*selectedName.price+数量*selectedName.price*12/100)*5/100)}/-

最终成本{{quantity*selectedName.price+quantity*selectedName.price*12/100-(quantity*selectedName.price+quantity*selectedName.price*12/100)*5/100}/-

var-app=angular.module('myApp',[]); 应用程序控制器('myCtrl',函数($scope){ $scope.fruit=[{名称:“橙色”,价格:80}, {名称:“Pinaple”,价格:100}, {名称:“葡萄”,价格:120}, {名称:“番石榴”,价格:80}, {名称:“芒果”,价格:95}, {名称:“苹果”,价格:180}, {名称:“香蕉”,价格:60}]; }); 非常感谢。
在控制器中,设置
ng model=“newItem.is\u active”的值。
不要脱口而出代码。添加一些文字来描述如何最好地回答所问的问题,这将有助于提高答案的长期价值,并有助于确保在审查过程中不会删除该答案。
$scope.selected = true; //put your selected condition