我正在嘗試使用角度更新來自文本框的json對象值,我不確定最好的方法是什麼。以角度更新json值
這是JSON對象...
$scope.productAttributes = {
"CostRequirements":[
{
"OriginPostcode": 'NW1BT',
"BearerSize":100
}
]
}
當在文本字段的使用類型和點擊一個按鈕,我想抓住這文本字段值,並將其傳遞到JSON對象,以取代postcose的值(OriginPostcode)我試圖通過一個範圍變量,但沒有奏效。
<input type="text" placeholder="Please enter postcode" class="form-control" ng-model="sitePostcode"/>
這是當用戶點擊一個按鈕提交JSON被解僱了溫控功能
var loadPrices = function() {
productsServices.getPrices1($scope.productAttributes)
.then(function (res) {
$scope.selectedProductPrices = res.data.Products;
// $scope.selectedProductAddOns = res.data.product_addons;
})
.finally(function() {
$scope.loadingPrices = false;
$scope.loadedPrices = true;
});
};
誰能告訴我什麼,我需要做的,把用戶在文本框中輸入成json對象?
非常感謝
似乎有從你的解釋缺少的組件......你有東西在你的代碼。例如角度控制器和按鈕來查看如何分配它來運行該功能。 – SoluableNonagon 2015-02-06 16:38:46
抱歉 - loadPrices和productAttributes坐在同一個控制器中。 – 2015-02-06 16:40:38
我更新了我的答案,它顯示了一種方法,可以正確地從作用域'抓取'值,並通過單擊按鈕來更新json。 – SoluableNonagon 2015-02-06 16:58:53