How to get paragraph data in textarea in angularjs?

拥有回忆 提交于 2019-12-02 19:04:12

问题


how can I get paragraph content text in textarea value

<p ng-model="extrap" >Some parragraph content</p>
<textarea ng-model="oneps"></textarea>
<script>
(function() {
    angular
        .module("TextAngularDemo", ['textAngular'])
        .controller("DemoController", ['$scope', 'textAngularManager', DemoController]);

    function DemoController($scope, textAngularManager) {
        $scope.oneps = {{extrap}}
    };
})();
</script>

I want paragraph text in textarea box with prefilled paragraph text


回答1:


I think you need to load a paragraph and text area with the same content, but you don't need to update the paragraph while the textarea value is changed. In that case you can go for one way data binding in angular js.

This can be achieved by adding :: inside your interpolation symbol like {{::yourModalValue}}

See the example below to see the implementation.

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.myParagraphContent = "Some initial content.";
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">

<b>Change the text area fild and see the change in me</b>
<p>{{myParagraphContent}}</p>

<b>Change the text area fild and see I won't be changes</b>
<p>{{::myParagraphContent}}</p>

<textarea ng-model="myParagraphContent"></textarea>

</div>


来源:https://stackoverflow.com/questions/58480823/how-to-get-paragraph-data-in-textarea-in-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!