javascript \ n中的换行符不起作用

时间:2017-04-17 07:06:31

标签: javascript angularjs ionic-framework

我正在尝试使用角度使用范围在javascript中执行换行符,因此它使用离子显示在我的前端。但它不起作用。还有另一种方式来打破这个。

$scope.pick= [
{
 name:"Fear",
 line:"\n\u2022 Do what you are afraid of doing...\n over and over."
}]

html

  <div class="list">
 <div class="item item-input item-select">
  <div class="input-label">

   </div>

  <select ng-model="tab" ng-init="tab=pick[0]" ng-options="tab.name for tab in pick"></select>
  </div>

 <div class="list list-inset">
 <div class="item">

<input type="text" ng-model="tab.line" id="displaycard">


<input type="text" ng-model="tab.line2" id="displaycard">

<input type="text" ng-model="tab.line3" id="displaycard">

</div>
</div>

</div>

尝试

    var somebreak = '<br />' + '\u2022 Do what you are afraid of doing...' + 
     '<br />'+ 'over and over.'

      $scope.pick= [{
      {
       name:"Fear",
       line: somebreak,
       }]

试过

     line:"<br/>\u2022 Do what you are afraid of doing...<br/> over and over.",

它仍然吐出这个。  enter image description here

3 个答案:

答案 0 :(得分:0)

使用<br/>

$scope.pick= [
{
 name:"Fear",
 line:"<br/>\u2022 Do what you are afraid of doing...<br/> over and over."
}]

使用ng-bind-html

一个简单的例子,而不是我:http://plnkr.co/edit/CO5WUCgBnOEJrVoKKrEE?p=preview

答案 1 :(得分:0)

按照下面的说明分配字符串值,并使用数组中的变量来保持其清洁

var someVar = '<br />' + '\u2022 Do what you are afraid of doing...' + '<br />'+ 'over and over.'

$scope.pick= [ {  
name:"Fear", 
line:someVar }]

答案 2 :(得分:0)

  var somebreak = "<br>"+"\u2022 Do what you are afraid of doing..."+"
  <br>"+"over and over."

  $scope.pick= [{

       name:"Fear",
       line: somebreak

  }]