Plnkr: http ://plnkr.co/edit/6xe46opL2kpgQrf7VaEu?p=preview
我有一个ng-click="switchCurreny()
函数,我正在尝试处理一个 HTML 块,该块放置在另一个 HTML 块内,该块嵌入在我的directive
.
我的app-main
控制器将另一个 HTML 块放入放置 HTML 的指令中,还包含ng-click
我正在尝试使用的功能:
var app = angular.module('app-main', ['ngAnimate', 'wallet-directives'])
.controller('MainCtrl', ['$scope', '$sce', function($scope, $sce) {
var vm = $scope;
var currency = 'USD';
vm.modal = false;
vm.modal_send = false;
vm.modalActive = false;
// HTML to be placed inside of directive placed HTML in <wallet-modals>
var send_html = '<div ng-click="switchCurreny()" class="btn_usd noselect">'+currency+'</div>';
// Open the modal, then place send_html into modal_bind:
vm.openModal = function($event) {
vm.modal = true; // show modal
vm.modal_send = true; // show modal_send
vm.modal_bind = $sce.trustAsHtml(send_html); // stick send_html inside of modal_bindd
}
vm.closeModal = function() {
vm.modal = false;
vm.modal_send = false;
};
// ng-click function inside of send_html:
vm.switchCurreny = function() {
console.log('clicked');
if (currency === 'USD') {
currency = 'BTC';
} else {
currency === 'USD';
}
};
}]);
我的模态 HTML 指令
(function() {
var app = angular.module('wallet-directives', [])
.directive('walletModals', function () {
return {
restrict: 'E',
template: '<div ng-show="modal_send" class="modal"><p>The Modal, button below:</p><br/><div ng-bind-html="modal_bind"></div></div>'
};
});
})();
HTML
<!-- Directive goes here -->
<wallet-modals></wallet-modals>