我正在尝试使用角度更新来自文本框的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