我不能讓我的模型在我選擇一個選項時進行更新。如何在Angularjs中使用ng選項時更新ng模型?
這是我的觀點:
<select data-ng-model="period" ng-options="item.value as item.text for item in periodOptions"></select>
在我controller.js我有以下幾點:
$scope.periodOptions = [
{ text: "This week", value: 'week' },
{ text:"This month", value: 'month '},
{ text:"This year", value: 'year' },
{ text:"All times", value: 'all-time '}
];
$scope.Search = function() {
return $http({
url: '/api/get',
method: 'GET',
params: {
period: $scope.period
}
}).then(function(response) {
console.log(response);
}, function(reason) {
alert(reason);
});
};
的$ scope.period不採取選擇了該選項的值來自用戶。我花了很多時間在這方面,無法弄清楚爲什麼會發生這種情況。
正常工作:http://plnkr.co/edit/5IHYM086JgMzlPdFfACo?p=preview – dfsq 2015-02-23 10:34:53
http://jsfiddle.net/HB7LU/11190/ – 2015-02-23 10:36:45
燦你使用params:{ 'period':$ scope.period } – JayKay 2015-02-23 10:37:30