我是angularjs的新手。我想要做的是当我从selectbox1中选择一个选项并且selectbox2的值根据selectbox1中的值而改变时。Angularjs选择选项问题
对于实施例:如果用户从selectbox1和selectbox2选择前端需要显示的值是'css, jquery, html, angularjs'
,但在这里,当我请从selectbox1任何选项。它显示'php, ruby, c#, python'
,任何想法我做错了什么。请帮帮我。
angular.module("ctrl", [])
.controller("appsctrl", function ($scope) {
$scope.data = {
frontend: [{ id: 1, name: 'css' }, { id: 2, name: 'jquery' }, { id: 3, name: 'html' }, { id: 4, name: 'angularjs' }],
Server: [{ id: 1, name: 'php' }, { id: 2, name: 'ruby' }, { id: 3, name: 'c#' }, { id: 4, name: 'python' }]
};
$scope.selectvalues = function() {
angular.forEach($scope.data, function (value, key) {
$scope.values = value;
});
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="ctrl" ng-controller="appsctrl">
<div class="selectvalues">
<select class="form" ng-model="select" ng-change=selectvalues()>
<option value="">Select</option>
<option value="FrontEnd">FrontEnd</option>
<option value="Server">Server</option>
</select>
<select class="form" ng-model="select_list">
<option value="">Select</option>
<option ng-repeat ="value in values" value ="{{value.name}}">{{value.name}}</option>
</select>
</div>
</div>
嘛,想想你的代码做什么:当selectvalues()被调用,它不使用什么在第一个选择框中选择的用户,将其存储到$范围。选择。相反,它只是遍历$ scope.data的所有值并将最后一个存储在$ scope.values中。 –