このようなhtmlにバインドするデータを取得するためにサービスを使用しています
{{order.Notes}}
order.Notes には複数行のテキストが含まれている可能性があるため、html タグ「br」を使用してフォーマットしたいと思います
これは私が使用しようとしているディレクティブです:
angular.module('directives', [])
.directive('htmlText', function () {
return {
restrict: 'E',
template: '<div ng-bind-html-unsafe="html"></div>',
scope: {
text: '='
},
link: function (scope, elem, attrs) {
var updateText = function () {
if (scope.text != null) {
scope.html = scope.text.replace('\n', "<br/>");
}
};
scope.$watch('text', function (oldVal, newVal) {
if (newVal) {
updateText();
}
});
}
};
});
<html-text text="order.Notes"></html-text>
ただし、newVal は常に null です。ここで何が欠けていますか?