我创建了一个显示消息的指令,并且它可以呈现任何带有角度属性的html消息,它可能包括按钮,锚标签(带有ng-clicks属性)等等.
index.html的:
irErrorPanel.tpl.html:
THE MESSAGE IS:
irErrorPanel.js:
angular.module('ng-iridize-common.directives').directive('irErrorPanel', ['$sce', function($sce) { return { restrict: 'E', templateUrl: 'irErrorPanel.tpl.html', controller: ['$scope', '$log', function($scope, $log) { var _this = this; _this.applyMessageText = function applyMessageText() { $scope.textHtmlSafe = $scope.status && $scope.status.text ? $sce.trustAsHtml($scope.status.text) : ""; }; _this.applyMessageText(); $scope.$watch("status.text", function(newValue, oldValue) { if (newValue === oldValue) { return; } if (!newValue) { $scope.textHtmlSafe = ""; return; } _this.applyMessageText(); }); }], link: function(scope, iElement, iAttrs, ctrl) { //call service and check box status. scope.$watch("status.text", function(value) { $compile(iElement.contents())(scope); }) } } }]);
例如,当状态为:"click!"时,它呈现完全正常,但ng-click不会触发任何内容.