次の角度設定があります。
var app = angular.module('app', []);
app.filter('unsafe', function($sce) {
return $sce.trustAsHtml;
});
app.controller('SearchController', ['$scope', '$http', function($scope, $http) {
$scope.searchString = '';
$scope.searchType = 'Artist';
$scope.updateHtml = function() {
$http.get('/search', {
params: {
searchString: $scope.searchString,
searchType: $scope.searchType
}
}).success(function(data) {
$scope.html = data;
}).error(function(err){
$scope.html = err;
});
};
$scope.updateHtml();
}]);
app.directive('searchDirective', function() {
return {
restrict: 'A',
transclude: true,
template: '<div ng-bind-html="html | unsafe" ng-transclude></div>'
};
});
コントローラーの ajax を介して生の html マークアップを取得し、@scope.html
. ディレクティブでは、この html が を通じて DOM に挿入されますng-bind-html
。
html (jade) は次のようになります。
#search(ng-controller="SearchController" search-directive)
それは基本的に機能します。しかし、含まれているこのhtmlの中に、私は{{searchType}}
解決したいようなトランスクルーシブなコンテンツがあります。残念ながらそうではなく、ブラウザに「{{searchType}}」と表示されます。トランスクルージョンを機能させるために何を変更できますか?
$compile
とについて読みまし$transclude
たが、使い方がわかりません。問題の解決に役立つかどうかもわかりません。どうも!