简体   繁体   中英

Assigned paragraph value in javascript variable

Hi I am using django with an internal angularjs in it. however I fail to assign my django variable to angularjs variable. Sorry It is difficult for me to explain it well. This is my code instead

I intarpolate tag from {{ to {$ , so angularjs and django wont have any conflict.

djangoVariable - this is taken from textarea that contain a lot of text and multiple line paragraph

html file

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

<script>

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

    $scope.description= {{djangoVariable}};

})

</script>

The problem is, the value is not showing.

I hope I explained it well. Thank you in advance

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

This must be failing because {{djangoVariable}} creates some spaced texts which javascript failed to understand, if you put the variable in "", it should understand. Try this

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

<script>

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

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

})

</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM