AngularJS with Django - Conflicting template tags

前端 未结 12 2141
南笙
南笙 2020-11-22 13:39

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

12条回答
  •  无人及你
    2020-11-22 14:26

    So I got some great help in the Angular IRC channel today. It turns out you can change Angular's template tags very easily. The necessary snippets below should be included after your angular include (the given example appears on their mailing lists and would use (()) as the new template tags, substitute for your own):

    angular.markup('(())', function(text, textNode, parentElement){
      if (parentElement[0].nodeName.toLowerCase() == 'script') return;
      text = text.replace(/\(\(/g,'{{').replace(/\)\)/g, '}}');
      textNode.text(text);
      return angular.markup('{{}}').call(this, text, textNode, parentElement);
    });
    
    angular.attrMarkup('(())', function(value, name, element){
        value = value.replace(/\(\(/g,'{{').replace(/\)\)/, '}}');
        element[0].setAttribute(name, value);
        return angular.attrMarkup('{{}}').call(this, value, name, element);
    });
    

    Also, I was pointed to an upcoming enhancement that will expose startSymbol and endSymbol properties that can be set to whatever tags you desire.

提交回复
热议问题