Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在angularjs中设置select的默认值_Javascript_Angularjs - Fatal编程技术网

Javascript 如何在angularjs中设置select的默认值

Javascript 如何在angularjs中设置select的默认值,javascript,angularjs,Javascript,Angularjs,我有这个: <select class=" text-center form-control" name="custname" ng-model="a.custid" ng-init="devcustname[0].customer_name" ng-change="fetchassocd(a)"> <option value="" selected="true">Please se

我有这个:

  <select class=" text-center form-control" name="custname"
            ng-model="a.custid" 
            ng-init="devcustname[0].customer_name"
            ng-change="fetchassocd(a)">

     <option value="" selected="true">Please select a Customer name</option>
     <option ng-repeat="a in devcustname | orderBy:['customer_name']"
            value="{{a.customer_id}}">{{a.customer_name}}
    </option>
  </select>
我希望默认值为devcustname[0]。客户名称。ng init不工作。当devcustname[0].customer\u name为null或未定义时,我希望“请选择一个显示为默认值的客户名称”

如果使用ng选项,则无法显示,请选择客户名称。

角度.模块'app',[].控制器'ctrl',函数$scope{ $scope.devcustname=[ {客户id:3,客户名称:,客户电子邮件:fas@gmail.com,联系电话:23,地址:f4}, {客户id:4,客户名称:ab,客户电子邮件:sm,联系电话:12,地址:第1行:R V路,第10十字路口}, {客户id:5,客户名称:da,客户电子邮件:3a@gmail.com,联系电话:33,地址:f4} ]; $scope.a={custid:4}; } -请选择客户名称- {{a.customer_name}}
ng init=devcustname[0]。客户名称| | a.custid=并请选择一个客户name@SlavaUtesinov即使存在值,ng init也不起作用。devcustname中的值是什么?@Sajeetharan看到这个@Nobody,我的答案是否提供了正确的/期望的行为?@Nobody,我在我的答案中复制了你的Plunk。