嵌套ng-repeat内的角ng-bind-html

约翰23

所以我在ng-repeat中有一个ng-repeat。内部ng-repeat引用“ recipe.ingredients中的项目”。问题在于,每个“项目”都有特殊字符,除非我使用ng-bind-html,否则它们不会呈现。但是,当我尝试使用ng-bind-html时,它不起作用。这是html:

这有效,但不能正确显示特殊字符(成分测量的分数):

<div class="row" ng-repeat="recipe in recipes">
    <h1 class='title'> {{ recipe.title }} </h1>
    <div class="col-md-5">
        <div class="list-group">
            <div class="list-title">Ingredients</div>
            <p class="list-group-item" ng-repeat="item in recipe.ingredients">{{item}}</p>
        </div>
    </div>
</div>

我尝试使用ng-bind-html代替(不起作用):

<div class="row" ng-repeat="recipe in recipes">
    <h1 class='title'> {{ recipe.title }} </h1>
    <div class="col-md-5">
        <div class="list-group">
            <div class="list-title">Ingredients</div>
            <p class="list-group-item" ng-repeat="item in recipe.ingredients" ng-bind-html="item"></p>
        </div>
    </div>
</div>

ng-repeat中“项目”的示例:

       {
            id: 1,
            img: "images/beefThumbnail.jpg",
            title: "Potatoes Supreme",
            servings: "Servings: 8 - 10",
            ingredients: [
                "6 medium potatoes, peeled",
                "Salt",
                "&frac12; cup butter or margarine, melted",
                "2 cups shredded Cheddar cheese",
                "&frac13; cup chopped green onion",
                "1 pint sour cream",
                "&frac14; teaspoon pepper",
                "&frac12; teaspoon salt"
            ],
            directions: [
                "Oven 350&#176;",
                "Cook potatoes in boiling salted water until done",
                "The next day grate potatoes coarsely",
                "Mix with remaining ingredients",
                "Place in shallow 1.5 or 2 quart baking dish and bake about 35 minutes"
            ]
        },//end potatoesSupreme
萨米尔·阿拉杰莫维奇(Samir Alajmovic)

使用$ sce,也不要忘记将其注入控制器

JS

$scope.trustAsHtml = $sce.trustAsHtml

然后用HTML

<div class="row" ng-repeat="recipe in recipes">
    <h1 class='title'> {{ recipe.title }} </h1>
    <div class="col-md-5">
        <div class="list-group">
            <div class="list-title">Ingredients</div>
            <p class="list-group-item" ng-repeat="item in recipe.ingredients" ng-bind-html="trustAsHtml(item)"></p>
        </div>
    </div>
</div>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

ng-repeat中唯一的ng-bind-html

来自分类Dev

ng-bind-html与{{interpolation}}

来自分类Dev

角ng-bind-html-unsafe表达式

来自分类Dev

ng-repeat 嵌套的 HTML 元素

来自分类Dev

AngularJS:ng-bind-html内的tooltip-html-unsafe

来自分类Dev

AngularJS中ng-bind,ng-bind-html,ng-bind-html-unsafe之间的区别?

来自分类Dev

AngularJS中ng-bind,ng-bind-html,ng-bind-html-unsafe之间的区别?

来自分类Dev

ng-bind-html与bind-html-compile?

来自分类Dev

AngularJS在元素上嵌套ng-bind

来自分类Dev

输入文本内的ng-bind-html不绑定

来自分类Dev

输入文本内的ng-bind-html不绑定

来自分类Dev

ng-repeat和ng-bind-html的手风琴无法正常工作

来自分类Dev

ng-repeat,使用ng-bind-html作为标记前和标记后

来自分类Dev

ng-bind-html使用无法识别ng-repeat形式的临时变量的函数

来自分类Dev

ng-bind-html使用无法识别ng-repeat形式的临时变量的函数

来自分类Dev

AngularJS ng-bind-html-unsafe替换

来自分类Dev

如何使用ng-bind-html?

来自分类Dev

如何从指令观看ng-html-bind?

来自分类Dev

ng-html-bind省略样式标签

来自分类Dev

ng-bind-html剥离元素属性

来自分类Dev

ng-bind-html无法正常工作

来自分类Dev

ng-bind-html中的AngularJS指令

来自分类Dev

Angular:对ng-bind-html使用transclude

来自分类Dev

Problems with modal and ng-bind-html

来自分类Dev

模态和ng-bind-html的问题

来自分类Dev

$ sce.trustAsHtml与ng-bind-html

来自分类Dev

ng-bind-html剥离元素属性

来自分类Dev

没有html元素的有角ng-repeat

来自分类Dev

使用嵌套的ng-Repeat生成HTML结构