javascript
  • jquery
  • html
  • angularjs
  • 2017-03-07 97 views 0 likes 
    0

    我有一个选择菜单。设置默认值时不显示下拉菜单文本 - AngularJS

    <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


    结果现在:

    enter image description here

    结果,我希望它是:

    enter image description here

    还有什么我应该看看进一步调试?

    +0

    我正在使用Chrome。 – ihue

    回答

    2

    我不喜欢这个 -

    在您的角度控制器

    $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脚本下控制选择降不正确的做法。在角度上,我们有ng选项,请参阅documentation

    +0

    你能否更新你的答案并详细解释一下? – ihue

    +0

    关于ng-options,请参阅此文档(https://docs.angularjs.org/api/ng/directive/ngOptions) – ISHIDA

    相关问题