如何在Angular 2模板中使用Django模板? [英] How to use Django templating inside Angular 2 template?

查看:79
本文介绍了如何在Angular 2模板中使用Django模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遍历视图渲染到HTML页面的django对象. 我以以下方式定义了Angular 2组件:-

I am trying to iterate through a django object rendered to an HTML page by the view. I defined an Angular 2 component in the following manner :-

@Component({

selector: 'search',
template:`

            <form [ngFormModel]="form" >
                  {% for category in categories_all %}
                  <li>
                    <div class="checkbox">
                      <label>
                        <input type="radio" name="category" 
                        id="category_{{category.id}}" 
                        value="{{category.name}}"
                        ngControl = "category"
                        #category="ngForm"
                        {% ifequal category.id|stringformat:"s"
                        param_values.category_id|stringformat:"s" %}
                         checked="checked"
                         {% endifequal %}
                         (click)="onClick()">
                 {{category.name}}
                      </label>
                    </div>
                  </li>{% endfor %}
            </form>
`,
providers:[ HTTP_PROVIDERS]


})

{% for category in categories_all %}是django模板语法,因此angular2无法识别它.有什么办法可以解决这个问题?

{% for category in categories_all %} is django templating syntax so angular2 is not identifying it. Is there any way to resolve this issue?

推荐答案

您应该定义自己的模板标签

you should define your own template tags like this

AngularJS模块(app.js)

AngularJS module (app.js)

angular.module('myapp', []).config(function($interpolateProvider) {
    $interpolateProvider.startSymbol('[[');
    $interpolateProvider.endSymbol(']]');
});

网页

<a>[[ variable ]]</a> 

这篇关于如何在Angular 2模板中使用Django模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆