在javascript变量中指定段落值

时间:2017-04-07 04:46:32

标签: javascript python html angularjs django

嗨我正在使用带内部angularjs的django。但是我没有将我的django变量赋给angularjs变量。对不起,我很难解释清楚。这是我的代码

我从{{{$进行了标记,因此angularjs和django不会有任何冲突。

djangoVariable - 这是从textarea中获取的,其中包含大量文本和多行段落

html文件

<div ng-controller="ProfileCtrl">
    <p>{$ description $} </p>
</div>

<script>

app
.controller('ProfileCtrl', function($scope){

    $scope.description= {{djangoVariable}};

})

</script>

问题是,该值未显示。

我希望我解释得很清楚。提前谢谢

2 个答案:

答案 0 :(得分:2)

<div ng-controller="ProfileCtrl">
    <p>{{ description }} </p> //use from angular js
    <p>{% djangoVariable %} </p> // Use from directly views.py
</div>

<script>

app
.controller('ProfileCtrl', function($scope){

    $scope.description= "{{djangoVariable}}";

})

</script>

答案 1 :(得分:1)

这一定是失败的,因为{{djangoVariable}}创建了一些javascript无法理解的间隔文本,如果你把变量放在&#34;&#34;,它应该理解。试试这个

<div ng-controller="ProfileCtrl">
    <p>{$ description $} </p>
</div>

<script>

app.controller('ProfileCtrl', function($scope){

    $scope.description= "{{djangoVariable}}";

})

</script>
相关问题