我有两种从远程服务获取数据的方法。
Api.types()返回我[{name:'vegetable',id:0},{name:'fruit',id:1}]。基于该返回并且如果我更改所选类型,它应该使用有关水果/蔬菜的数据更新种类字段数据。该代码出了什么问题?
controller('MainCtrl', ['$log', 'Api', function($log, Api) {
this.formFields = [
{
key: "type",
type: "select",
templateOptions: {
label: "Types",
valueProp: "id",
labelProp: "name",
options:[],
},
expressionProperties: {
'templateOptions.options': function($viewValue, $modelValue, scope) {
Api.types()
.then(function(ok) { scope.to.options=ok;}, function(error){});
}
},
},
{
key: "variety",
type: "select",
templateOptions: {
label: "variety",
valueProp: "id",
labelProp: "name",
options:[],
},
expressionProperties: {
'templateOptions.options': function($viewValue, $modelValue, scope) {
Api.variety(scope.model.type)
.then(function(ok) { scope.to.options=ok;}, function(error){});
}
},
}
];
});
答案 0 :(得分:0)
你没有归还任何东西。
expressionProperties: {
'templateOptions.options': function($viewValue, $modelValue, scope) {
$scope.to.options=[]; //reset to avoid having issues when selecting
return Api.variety(scope.model.type)
.then(function(ok) {
scope.to.options=ok;
return $scope.to.options;
}, function(error){});
}
},