我有一个精选菜单。
<select id="dd" ng-show='data != null' ng-model='search'></select>
我默认触发了美国过滤器
$scope.search = 'United States of America';
到目前为止,过滤器似乎可以工作,但我的 jQuery 似乎都不起作用。
$scope.search = 'United States of America';
$("#dd").val('United States of America');
$("#dd").attr("selected","selected");
您可能会看到我在这里的内容:JSFiddle
<小时/>现在结果:
我想要的结果是:
我还应该研究什么来进一步调试?
最佳答案
我会这样做 -
在你的 Angular Controller 中
$scope.timeFrames = [{ "id": 1, "name": "USA" }, { "id": 2, "name": "UK" }, { "id": 3, "name": "China" }];
$scope.selectedTimeFrame = 1;
在你的html页面
<select ng-model="selectedTimeFrame" ng-change="frame()" ng-options="timeFrame.id as timeFrame.name for timeFrame in timeFrames" ng-cloak></select>
尝试通过java脚本控制选择下拉列表不是正确的方法。在Angular中,我们有ng-options,请引用这个documentation .
关于javascript - 设置默认值时,下拉菜单文本不显示 - AngularJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42658820/