[英]how to execute a string in angular js directive
I am dynamically building a string which is given below 我正在动态构建下面给出的字符串
scope.gridOptions = {columnDefs : [ {
field : username,
displayName :USERNAME
} ]};
and storing in a string myvalue. 并存储在字符串myvalue中。
My requirement is that compiler has to execute this but it is treating as a string. 我的要求是编译器必须执行此操作,但它将视为字符串。 So please suggest me how to execute a string in angular js 所以请建议我如何在angular js中执行字符串
You can use JSON.parse 您可以使用JSON.parse
scope.gridOptions = JSON.parse(yourString); scope.gridOptions = JSON.parse(yourString);
it's unclear what you meant by saying "executing string". 不清楚您所说的“执行字符串”是什么意思。
First, when i saw the title i thought of JavaScript eval
function ( link ) 首先,当我看到标题时,我想到了JavaScript eval
函数( link )
Afterwards, when i read the question, it seems you are looking to convert from/to a JSON ( what is JSON ) 之后,当我阅读问题时,似乎您正在寻找从JSON转换成JSON( 什么是JSON )的信息
some suggested to use JSON.parse
. 一些建议使用JSON.parse
。 i recommend you not to use it in your angular code 我建议您不要在角度代码中使用它
alternative to JSON.parse
: 替代JSON.parse
:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.