如何连接数组中对象的两个属性,以用作角度JS的ngOptions中的标签?我尝试过以下代码,但在控制台中出错。
<select name=artArtist class=form-control ng-model=artArtist ng-options="art.firstName + ' ' + art.lastName for art in artists" required></select>
以下代码有效,但会生成第一个名称和姓氏之间没有空格的艺术家名称。我做错了什么?
<select name=artArtist class=form-control ng-model=artArtist ng-options="art.firstName + art.lastName for art in artists" required></select>
答案 0 :(得分:0)
尝试以下方法:
<select name="artArtist" class="form-control" ng-model="artArtist" ng-options="(art.firstName + ' ' + art.lastName) for art in artists" required></select>
答案 1 :(得分:0)
请检查您的控制器代码 我尝试了以下操作,没有错误。
<div ng-controller="MyCtrl">
<select name=artArtist class=form-control ng-model=artArtist ng-options="art.firstName + ' ' + art.lastName for art in artists" required></select>
</div>
function MyCtrl($scope) {
$scope.artists = [{firstName: 'Mike', lastName:'Random'},
{firstName: 'Lulu', lastName:'Byte'},
{firstName: 'Sonia', lastName:'Link'}];
}
试试这里 http://jsfiddle.net/1hempsf4/
否则发布您的错误。