Debojyoti Debojyoti - 1 year ago 87
Javascript Question

In angular js why does this javascript replace method to replace &nbsp works on the controller side but not on the template side

Template angular expression:

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

does not work

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


Answer Source

This does not work because angular expressions are not exactly same as javascript expressions. In your example you are trying to create a regular expression and evaluate it. As mentioned on angular documentation angular expressions do not allow No RegExp Creation With Literal Notation. And since angularjs expressions are forgiving no error is thrown but your code doesn't work silently

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download