0

I am submitting a form for job posting and have skills like C# which escape in my rest API. So I encoded the skills and sending to backend.

"skills":encodeURIComponent(skills)

now when I get back the skills I am doing decodeURIComponent for my skills

$scope.skills = decodeURIComponent(skills);

but this wont work with array of datas, when I want to fetch list of jobs , the datas comes in array , my array has almost 15 key values , which will be used in table some way. Writing a new array and pushing each values into array again pushing decoded skills a big process.

Is any solution to directly decoded the value in view , that is html

I tried {{decodeURIComponent(item.skills) }} but no luck.

sample Data ::

{
  "json": {
    "response": {
      "statusmessage": "Success",
      "count": 59,
      "data": [
        {
          "employerId": 2,
          "employerEmail": "[email protected]",
          "employerName": "SumitKumar",
          "companyName": "Infosoftjoin%20pvt%20ltd.",
          "jobId": 142,
          "jobTitle": "Test%20case%201",
          "jobDescription": "<p>ahdu%29%28@*%29*W%29%28*%29E%26%3D--%3D</p>",
          "link": "http://www.infosoftjoin.in",
          "numberOfPositions": 5,
          "createdTime": "18-May-2018",
          "lastUpdatedTime": "18-May-2018",
          "consumedCredits": 44,
          "location": {
            "city": "North And Middle Andaman",
            "state": "Andaman and Nicobar Islands",
            "country": "India"
          },
          "skills": [
            "C%23.NET"
          ],
          "approved": 1,
          "status": "Approved"
        },
        {
          "employerId": 2,
          "employerEmail": "[email protected]",
          "employerName": "SumitKumar",
          "companyName": "Infosoftjoin%20pvt%20ltd.",
          "jobId": 130,
          "jobTitle": "New%20job",
          "jobDescription": "hryuyurfkituo8",
          "link": "http://www.infosoftjoin.in",
          "numberOfPositions": 5,
          "createdTime": "16-May-2018",
          "lastUpdatedTime": "16-May-2018",
          "consumedCredits": 93,
          "location": {
            "city": "Nicobar",
            "state": "Andaman and Nicobar Islands",
            "country": "India"
          },
          "skills": [
            "APACHE TOMCAT"
          ],
          "approved": 1,
          "status": "Approved"
        }

      ]
    }
  }
}
3
  • 1
    Couldn't this be done in a loop or a .map call? Can you provide sample data? Commented May 18, 2018 at 10:33
  • included sample data Commented May 18, 2018 at 10:54
  • In general the AngularJS framework automatically percent encodes within the $http service. There should be no need to use encodeURIComponent. Show us the code for sending data to the backend. Commented May 18, 2018 at 11:03

1 Answer 1

1

encodeURIComponent is a JavaScript built-in function, you can not access it directly in your AngularJs template. Convert that into a $scope function then try accessing from AngularJs template.

I would suggest you to have a filter for the same instead of $scope function.

Filter:

app.filter('decodeFilter', function() {
    return function(input) {
        return decodeURIComponent(input);
    };
});

Template:

{{item.skills | decodeFilter}}

If still you want that as $scope function then try below code:

Controller:

$scope.decodeComponent=function(value){
    return decodeURIComponent(value);
}

Template:

{{decodeComponent(item.skills)}}

Also, please check this plunker for sample scenario with the above examples.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.