2
我有兩種方法從遠程服務獲取數據。 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){});
}
},
}
];
});
而不是做'Api.types()。然後(函數(OK){scope.to.options = ok;},函數(錯誤){});'嘗試簡單'返回Api.types( )' – kentcdodds