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

时间:2016-03-30 04:20:26

标签: javascript ruby-on-rails angularjs ruby slim-lang

我目前在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] }}

1 个答案:

答案 0 :(得分:1)