NG-INIT JSON对象 [英] ng-init json Object
本文介绍了NG-INIT JSON对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用angularjs(NG-INIT),我想将值分配给变量jsonObj。
I use angularjs (ng-init) and I want to assign value to variable as jsonObj.
我试试这一个,但它不工作。
I try this one but it doesn't work.
ng-init="percentObj = [{ "value":40,"color":"#F5A623" },{ "value":60,"color":"#F5A623" }];
和另外一个问题
我要像
and another question I want to assign value like
percentObj = [{ "value": parseInt($scope.projectData[0].value),"color":"#F5A623" },{ "value": parseInt($scope.projectData[0].value),"color":"#F5A623" }]
如何解决这个问题?
How to fix this problem??
THX
推荐答案
您可以使用窗口对象设置JSON:
You can use window object for set your 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
};
}
这篇关于NG-INIT JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文