简体   繁体   English

Angular-允许用户输入CSS以生成动态模板

[英]Angular—allow users to input CSS for dynamic template generation

For security reasons, Angular documentation clearly states to ...not use user input to generate templates dynamically . 出于安全原因,Angular文档明确声明 ...not use user input to generate templates dynamically However, I want to do just that. 但是,我只想这样做。 I would like to allow users to use input fields to generate CSS freely and use it to create their own templates, which they could then download. 我想允许用户使用输入字段自由生成CSS,并使用它来创建自己的模板,然后可以下载它们。 I know $sanitize works to clean HTML, but I am not aware if there is anything that allows you to do this with CSS, that will protect the site from security vulnerabilities. 我知道$sanitize可以清除HTML,但是我不知道是否有任何可以使用CSS做到这一点的东西,这可以保护网站免受安全漏洞的侵害。

Is it possible? 可能吗?

Thanks in advance. 提前致谢。

You can preview user inputted templates with style tags. 您可以预览用户输入的带有样式标签的模板。 I've used $templateCache to load user html. 我使用$ templateCache加载用户html。

 $scope.loadTemplate=function(){
       var randomStringName=makeid();
       $scope.templVar=randomStringName;
       $templateCache.put(randomStringName,$scope.templ);
 }

HTML HTML

  <div ng-include="templVar"></div>

在此处输入图片说明 http://plnkr.co/edit/8HP7HWwMvlXYiusE9TGH?p=preview http://plnkr.co/edit/8HP7HWwMvlXYiusE9TGH?p=preview

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM