直接在view/html中解码编码值

Decode the encoded value directly in view/html

我正在提交职位发布表格,并且拥有 C# 这样的技能,在我休息时可以逃脱 API。所以我编码了技能并发送到后端。

"skills":encodeURIComponent(skills)

现在当我找回我正在做的技能时 decodeURIComponent skills

$scope.skills = decodeURIComponent(skills);

但这不适用于数据数组,当我想获取作业列表时,数据出现在数组中,我的数组有将近 15 个键值,它们将以某种方式在 table 中使用。编写一个新数组并将每个值再次推入数组,将解码技能推向一个大过程。

有没有办法直接解码视图中的值,即html

我尝试了 {{decodeURIComponent(item.skills) }} 但没有成功。

样本数据::

{
  "json": {
    "response": {
      "statusmessage": "Success",
      "count": 59,
      "data": [
        {
          "employerId": 2,
          "employerEmail": "sumit@infosoftjoin.in",
          "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": "sumit@infosoftjoin.in",
          "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"
        }

      ]
    }
  }
}

encodeURIComponent 是一个 JavaScript 内置函数,您无法在 AngularJs 模板中直接访问它。将其转换为 $scope 函数,然后尝试从 AngularJs 模板访问。

我建议您使用相同的过滤器而不是 $scope 函数。

过滤器:

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

模板:

{{item.skills | decodeFilter}}

如果您仍然希望它作为 $scope 函数,请尝试以下代码:

控制器:

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

模板:

{{decodeComponent(item.skills)}}

此外,请检查 this plunker 以获取包含上述示例的示例场景。