[英]How to update global JSON field in angular js with JSON objects from different views
I have defined a global JSON object. 我已经定义了一个全局JSON对象。 I want to write a function that allows the user to click a button and the master JSON object gets an ujpdate.
我想编写一个函数,允许用户单击一个按钮,主JSON对象获取一个ujpdate。
$scope.masterJsonObj=[];
$Scope.myfunction=function($scope){
$scope.masterJsonObj= $scope.formdataJson + $scope.secondJsonObj + $scope.thirdJsonObj
final json object should look like this 最终的json对象应该是这样的
[
{
fName: "firstname",
lName: "lastname",
id: "userId",
secondJsonObj : [
{
bankAccount: "some bank",
bankAccountNumber: "12334",
Status: "true"
},
{
bankAccount: "some bank2",
bankAccountNumber: "212334",
Status: "false"
}],
thirdJsonObj[{
addrone: "some treet",
addr2: "house number"
}]
}
]
Use $rootScope as you can simply inject it into any controller and change values in this scope. 使用$ rootScope,只需将其注入任何控制器并更改此范围内的值即可。
$rootScope is a parent of all scopes so values in rootscope will be accessible in all controllers. $ rootScope是所有范围的父级,因此可以在所有控制器中访问rootscope中的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.