2016-11-10 83 views
1

我正在尝试创建两个下拉下降与主题和另一个视频。这些视频将按照主题进行过滤。预先感谢您的帮助。角度级联下拉

 <md-input-container flex> 
      <label>Topic</label> 
      <md-select ng-model="selected.topic" required ng-change="getVideosByTopicId(selected.topic)"> 
       <md-option ng-repeat="topic in topics" value="{{topic.TopicID}}">{{topic.TopicName}}</md-option> 
      </md-select> 
     </md-input-container> 
     <md-input-container flex> 
      <label>Video</label> 
      <md-select ng-model="selected.video" required > 
       <md-option ng-repeat="video in videos" value="{{video.VideoID}}">{{video.Name}}</md-option> 
      </md-select> 
     </md-input-container> 

这是控制器

function getVideosByTopicId(topicId) { 
    return $http.post(baseUrl + 'Test/getVideosByTopicId', topicId).then(function (response) { 
     return $.parseJSON(response.data); 
    }); 
} 
+1

如果一切都很好,你的js代码,然后分配给响应$ scope.videos在ng-repeat中使用 –

回答

2

你可以做到这一点,

<md-select ng-model="type" > 
    <md-option ng-value="k" data-ng-repeat="(k,v) in videos">{{ k }}</md-option> 
</md-select> 
    <md-select ng-model="metrics" > 
    <md-option ng-value="t" data-ng-repeat="t in level2">{{ t }}</md-option> 
</md-select> 

DEMO

+0

谢谢。哪一个更好用:观察或改变。你能不能给我一个带ng-change的例子。 – user6934713

+0

ng-change是建议的方式 – Sajeetharan

+0

你想用ng-change做什么? – Sajeetharan