AngularJS 与 Django - 模板标签冲突

AngularJS with Django - Conflicting template tags(AngularJS 与 Django - 模板标签冲突)

本文介绍了AngularJS 与 Django - 模板标签冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I want to use AngularJS with Django however they both use {{ }} as their template tags. Is there an easy way to change one of the two to use some other custom templating tag?

解决方案

For Angular 1.0 you should use the $interpolateProvider apis to configure the interpolation symbols: http://docs.angularjs.org/api/ng.$interpolateProvider.

Something like this should do the trick:

myModule.config(function($interpolateProvider) {
  $interpolateProvider.startSymbol('{[{');
  $interpolateProvider.endSymbol('}]}');
});

Keep in mind two things:

  • mixing server-side and client-side templates is rarely a good idea and should be used with caution. The main issues are: maintainability (hard to read) and security (double interpolation could expose a new security vector - e.g. while escaping of serverside and clientside templating by themselves might be secure, their combination might not be).
  • if you start using third-party directives (components) that use {{ }} in their templates then your configuration will break them. (fix pending)

While there is nothing we can do about the first issue, except for warning people, we do need to address the second issue.

这篇关于AngularJS 与 Django - 模板标签冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:AngularJS 与 Django - 模板标签冲突

基础教程推荐