2016-04-16 7 views
1

テンプレート角度式にコントローラ側で動作しますが、しません:なぜこのJavaScriptは交換する方法を置き換える&NBSPは、テンプレート側

function TodoCtrl($scope) { 
    $scope.notification = 'ujjal saha share own wall'; 
    $scope.notif = notification.noti_val.replace(/\&nb\s*sp;/g, '') 
} 

の作品は動作しません

<h2 style="white-space:normal"> 
    {{notification.noti_val.replace(/\&nb\s*sp;/g, ' ')}} 
</h2> 

答えて

2

編集しよう。あなたの例では、regular expressionを作成して評価しようとしています。 angular documentationangular expressionsで述べたように、No RegExp Creation With Literal Notationを許可しません。 anglejsの式がforgivingなのでエラーはスローされませんが、コードは自動的には機能しません

+0

ありがとうございますAditya。 – WebInsight

+0

私の喜び:)。 –

1

フィルタを作成するだけではどうですか?上の@AdityaSinghで述べたように、角度式はJavaScript式とまったく同じではないため、フィルタが作成されました。

JS:

angular.module('MODULE_NAME').filter('stripSpaces', function() { 
    return function(input) { 
     return input.replace(/\&nb\s*sp;/g, ''); 
    } 
} 

HTML:密接にあなたのコードで

{{notification.noti_val | stripSpaces}} 
+0

あなたの時間と洞察力に感謝の男 – WebInsight

0

ルック。

$scope.notification = 'ujjal saha&nbsp;share&nbsp;own&nbsp;wall'; 
$scope.notif = notification.noti_val.replace(/\&nb\s*sp;/g, ''); 

あなたは$scope.notification =を持っているが、後angular expressionsjavascript expressionsとまったく同じではありませんので、これは動作しませんnotification.noti_val

+0

それはちょっと誤字です。私はそれを編集しました。あなたの時間に感謝します。 – WebInsight

関連する問題