由网友(伱有毒と硪上瘾)分享简介:我用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...
我用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
};
}
相关推荐
最新文章