Ng-init json Object
I am using angularjs (ng-init) and I want to assign the value to a variable as jsonObj.
I try this one but it doesn't work.
ng-init = "percentObj = [{" value ": 40," color ":" # F5A623 "}, {" value ": 60," color ":" # F5A623 "}];
and one more question I want to assign a value like
percentObj = [{"value": parseInt ($ scope.projectData [0] .value), "color": "# F5A623"}, {"value": parseInt ($ scope.projectData [0] .value), " color ":" # F5A623 "}]
How to solve this problem?
thank
+3
source to share
4 answers
You can use window object to set json:
<script type="text/javascript">
window.data= {awesome:1};
</script>
:
<div ng-controller="myCntrl" ng-init="init('data')">
:
function myCntrl($scope) {
$scope.init = function (settings) {
settings = window[settings];
console.log(settings.awesome); //1
};
}
+2
source to share