【发布时间】:2016-05-26 15:28:56
【问题描述】:
我正在尝试在弹出窗口中创建一个选择器,并且我想通过调用不同的函数来收集事件,但是 ng-click 指令不起作用。 我阅读了 $ compiles 指令,但它对我不起作用,因为我不能同时使用这两个指令。
我的html:
<button uib-popover-html="htmlPopover" class="btn btn-default">HTML Popover</button>
我的Ctrl:
$scope.htmlPopover = $sce.trustAsHtml('<div class="picker">' +
'<div class="picker-items">' +
'<div class="picker-item" title=".fa-github"><i class="fa fa-github"></i></div>' +
'<div class="picker-item picker-selected label label-success" title=".fa-heart">' +
'<i class="fa fa-heart"></i></div><div class="picker-item" title=".fa-html5">' +
'<i class="fa fa-html5"></i></div><div class="picker-item" title=".fa-css3">' +
'<a ng-click=\"buttonClick()\"><i class="fa fa-css3"></i></a>' +
'</div></div></div>');
$scope.buttonClick = function(){
console.log("Well");
};
我的指令:
.directive('bindHtmlCompile', ['$compile', function ($compile) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
scope.$watch(function () {
return scope.$eval(attrs.bindHtmlCompile);
}, function (value) {
// In case value is a TrustedValueHolderType, sometimes it
// needs to be explicitly called into a string in order to
// get the HTML string.
element.html(value && value.toString());
// If scope is provided use it, otherwise use parent scope
var compileScope = scope;
if (attrs.bindHtmlScope) {
compileScope = scope.$eval(attrs.bindHtmlScope);
}
$compile(element.contents())(compileScope);
});
}
};
}]);
有人可以帮忙吗?
谢谢;P
【问题讨论】:
标签: javascript angularjs twitter-bootstrap