在javascript variab中指定段落值

2024-09-30 18:25:58 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我用的是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>

问题是,值没有显示出来。你知道吗

我希望我解释得很好。先谢谢你


Tags: django代码标记文本divscriptdescription段落
2条回答

这一定是失败的,因为{djangoVariable}}创建了一些javascript无法理解的间隔文本,如果将变量放入“”,它应该能够理解。试试这个

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

<script>

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

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

})

</script>
<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>

相关问题 更多 >