4

I am trying to retrieve value from a multi line textbox using angular js, but am getting the div tags attached to the content. How can we retrieve only the content?

I have used following code:

var myAngApp = angular.module('SharePointAngApp', []);

    myAngApp.controller('spCustomerController', function ($scope, $http) {

        $http({

            method: 'GET',

            url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Questions')/items?$select=Description",

            headers: { "Accept": "application/json;odata=verbose" }

        }).success(function (data, status, headers, config) {

            $scope.customers = data.d.results;


        }).error(function (data, status, headers, config) {



        });


});

I am getting the content along with html div tags, but I need only the content

3
  • $scope.customers.innerText or $scope.customers.innerHTML Sep 26, 2016 at 11:21
  • I tried this inside angular expression{{$scope.customers.Description.innerText}}, but it is showing empty
    – Dheeraj
    Sep 26, 2016 at 11:26
  • 1
    Do you rich text content as plain text? Sep 26, 2016 at 11:45

2 Answers 2

3

You are getting HTML content because you have enabled Enhanced rich text option in your column.

enter image description here

Solution No#1

Enable Plain text instead of Enhanced rich text

Solution No#2

Remove HTML tags using Regex

    var myAngApp = angular.module('SharePointAngApp', []);

myAngApp.controller('spCustomerController', function($scope, $http) {

    $http({

        method: 'GET',

        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Questions')/items?$select=Description",

        headers: {
            "Accept": "application/json;odata=verbose"
        }

    }).success(function(data, status, headers, config) {
      
      //remove all html tags
        data.d.results.forEach(function(customer) {
            customer["{InternalNameOfYourColumn}"] = customer["{InternalNameOfYourColumn}"].replace(/<(?:.|\n)*?>/gm, '');;
        });
      
        $scope.customers = data.d.results;


    }).error(function(data, status, headers, config) {



    });


});
2
  • And How can we query the data in another list based on the ID value retrieved from the first list?
    – Dheeraj
    Sep 26, 2016 at 12:39
  • Hi @Dheeraj, It's another question? Please ask a new question. I will try to answer. Sep 26, 2016 at 12:42
3

You can fetch value from description by using .text() function in the success of the function.. please refer below code

myAngApp.controller('spCustomerController', function ($scope, $http) {

    $http({

        method: 'GET',

        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('Questions')/items?$select=Description",

        headers: { "Accept": "application/json;odata=verbose" }

    }).success(function (data, status, headers, config) {

        $scope.customers = $(data.d.results[0].Description).text();


    }).error(function (data, status, headers, config) {



    });

Hope it will work for you .. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.