angularjs – ng-model和ng-options不匹配?

我在我的资源对象中有一个方法,它来自:

resources.type

otherstuff: 'more strings'
type:'specifictype'
morestuff: 'morestuff'

用户可以通过下拉列表/通过另一个调用来更改此类型,该调用获取所有可能类型的列表,这些类型看起来像resourceList.types,其中包含像json这样的对象列表

types:
     [
         {name:'resourcetype1'},{name:'resourcetype2'},etc...
     ],

我的HTML看起来像:

<select ng-model="resources.type" ng-options="name.name for name in resourceList.types">
</select>

选择/下拉框填充了我的resourceList.type内容,但是当页面加载时,ng-model没有设置为已选择的资源类型.实际上,当您单击时,它会在下拉列表的顶部选择一个空白条目.对此有棱界吗?如何让ng-model按照我想要的方式运行?

我尝试用不同的方法解决重复问题,但我觉得这更像是角度连接模型的方式.它是否只是将字符串与ng-options列表匹配?

这是plnkr,你可以看到它不是认为type1

http://plnkr.co/edit/NyWACtFQuyndR6CG8lpN?p=info

在Angular中,模型是真理的唯一来源.
这意味着如果您想要选择一个值(并绑定到您的ngModel),您需要将其分配给模型:
<select ng-model="resources.type"
        ng-options="type.name as type.name for type in resourceList.types">
</select>

$scope.resources = {...};
$scope.resourceList = {
    ...
    types: [
        {name: 'resourcetype1'},{name: 'resourcetype2'},...
    ]
};

// Set the model to the desired value
$scope.resources.type = $scope.resourceList.types[0].name;

另见这short demo.

相关文章

ANGULAR.JS:NG-SELECTANDNG-OPTIONSPS:其实看英文文档比看中...
AngularJS中使用Chart.js制折线图与饼图实例  Chart.js 是...
IE浏览器兼容性后续前言 继续尝试解决IE浏览器兼容性问题,...
Angular实现下拉菜单多选写这篇文章时,引用文章地址如下:h...
在AngularJS应用中集成科大讯飞语音输入功能前言 根据项目...
Angular数据更新不及时问题探讨前言 在修复控制角标正确变...