0
我具有其中用戶可以選擇一個ORDERBY濾波器一個選擇元件,NG-模型不是通過正確的值
%select{
"ng-change" => "select()",
"ng-model" => "selectedItem",
"ng-options" => "option.sortBy for option in listOfOptions"}
這是listOfOptions
$scope.listOfOptions = [
{sortBy: 'Release date', value:'release_date'},
{sortBy: 'Newly added', value:'created_at'}
];
而select
功能,
$scope.select = function(){
console.log($scope.selectedItem.value)
}
在視圖中,選擇框顯示發佈日期和新添加的選項,但是當我選擇其中之一,我得到的錯誤,
TypeError: Cannot read property 'value' of undefined
所以它看起來像$ scope.selectedItem是不確定的,但我想不出爲什麼。
如果我沒有弄錯selectedItem應該出現在這個不在$ scope對象中。 * this.selectedItem *應該爲你工作 –
你應該將ng-options改爲低於'「ng-options」=>「在listOfOptions中選擇」}' –
@從範圍改變到這個固定它。 – alucardu