本文介绍了转换json& amp;到&在AngularJS中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有value属性的HTML元素。值应该是Comfort&保护,但来自JSON获得结果的名称是Comfort & amp; 保护和AngularJS在我的视图中将其打印出来。

I have an HTML element that have value attribute. The value should be Comfort & Protection but the name that comes from the JSON get result is Comfort & Protection and AngularJS is printing it like this on my view.

我尝试将此名称放在html元素值属性中。

I try to put this name inside an html element value attribute.

<div ng-app="app">
    <div ng-controller="ExampleCtrl">
        <input type="text" ng-repeat="type in types" value="{{type.name}}" />
    </div>
</div>





var app = angular.module("app", []);

app.controller('ExampleCtrl', function($scope){
    $scope.types = [
        {
            id: 1,
            name: 'Comfort &amp; Protection'
        },
        {
            id: 2,
            name: 'Other Name'
        }
    ]
})

推荐答案

一种选择是用& 替换& amp; 字符串,如下所示:

One option would be to replace the &amp; string with & as below:

var text = name.replace(/&amp;/g, '&')

这篇关于转换json&amp; amp;到&amp;在AngularJS中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 16:57