我有一個表單,當用戶編輯表單並更新表單時。但是,我不想從app.js中獲取它。相反,我想從像「app.json」這樣的文件中抓取。如何從AngularJS中的JSON文件進行更新?
這裏是我的代碼:
<!DOCTYPE html>
<html>
<head>
<script data-require="[email protected]" data-semver="1.3.6" src="https://code.angularjs.org/1.3.6/angular.js"></script>
<link href="style.css" rel="stylesheet" />
<script src="script.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<input type="text" ng-model="myObject.sitePostcode"/>
<button ng-click='update()'>Update</button>
<div>Current Value: {{productAttributes.CostRequirements[0].OriginPostcode}}</div>
</div>
</body>
</html>
App.js
var app = angular.module("myApp", []);
app.controller('myCtrl', ['$scope', function($scope){
$scope.productAttributes = {
"CostRequirements":[
{
"OriginPostcode": 'NWU2017',
"BearerSize":100
}
]
}
$scope.myObject = {
sitePostcode : $scope.productAttributes.CostRequirements[0].OriginPostcode
};
$scope.update = function(){
$scope.productAttributes.CostRequirements[0].OriginPostcode = $scope.myObject.sitePostcode;
};
}]);
? – Sajeetharan
是的。正如我抓住我的app.js這是productAttributes。 –
顯示應該包含在文件中的json信息是什麼? – Sajeetharan