应用<strong>标记到我的js.coffee文件中的字符串

Apply <strong> tags to a string in my js.coffee file

本文关键字:coffee js 文件 字符串 我的 strong lt gt 应用      更新时间:2023-09-26

我目前在Ruby On Rails项目中使用Angular和Slim。我在js.coffee中有一系列问题,这些问题目前正在我的视图中呈现。

数组中的一个字符串具有强标记,但它没有在我的html中正确显示。

我得到的不是标准,而是。。。

On which Playfield is the <strong>Standard</strong> game played ?

我对棱角分明还很陌生,我缺少什么?

JAVASCRIPT

game_create_ctrl.js.coffee
angular.module('OombangularApp').controller 'GameCreateCtrl', [
  '$scope', '$sce', '$uibModal', 'Game', 'GameFormat', 'PlayfieldType', 'Persona',
  ($scope, $sce, $uibModal, Game, GameFormat, PlayfieldType, Persona) ->
    $scope.step = 1
    ###This works...when it is not an Array
    $scope.html = "On which Playfield is the " + "<strong>Standard</strong>" + " game played ?"
    $scope.stepQuestion = $sce.trustAsHtml($scope.html)        
    ###How do I show the <strong> tags in my view when its an array?
    $scope.stepQuestions = ['What should this Game be called?', 'What should this Game be called?',
                        'What category does this Game belong to?',
                        'On which Playfield is the <strong>Standard</strong> game played ?',
                        'What is the Player Configuration?', 'How is a <strong>Standard</strong> game won?', 'Which Persona owns this Game?']
]
    $scope.stepQuestions = $scope.stepQuestions.map (item) -> $sce.trustAsHtml(item)

视图

new.html.slim
form[name='gameCreateForm' ng-controller='GameCreateCtrl']
    ###This Works
    .question ng-bind-html="stepQuestion"{{ stepQuestion }}
    ###This doesnt
    .question ng-bind-html="stepQuestions"{{ stepQuestions[step - 1] }}

请尝试:angularjs输出纯文本而不是html(类似问题)或https://docs.angularjs.org/api/ng/directive/ngBindHtml