缩小后JavaScript函数不工作
我正在使用一个函数来触发模态窗口 链接:缩小后JavaScript函数不工作,javascript,angularjs,minify,Javascript,Angularjs,Minify,我正在使用一个函数来触发模态窗口 链接: <a ng-click="toggleModal()" href>complexity</a> 这将触发模式窗口: .directive('modal', function () { return { template: '<div class="modal fade">' + '<div class="modal-dialog">' + '
<a ng-click="toggleModal()" href>complexity</a>
这将触发模式窗口:
.directive('modal', function () {
return {
template: '<div class="modal fade">' +
'<div class="modal-dialog">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' +
'<h4 class="modal-title">{{ title }}</h4>' +
'</div>' +
'<div class="modal-body" ng-transclude></div>' +
'</div>' +
'</div>' +
'</div>',
restrict: 'E',
transclude: true,
replace:true,
scope:true,
link: function postLink(scope, element, attrs) {
scope.title = attrs.title;
scope.$watch(attrs.visible, function(value){
if(value === true) {
$(element).modal('show');
} else {
$(element).modal('hide');
}
});
$(element).on('shown.bs.modal', function(){
scope.$apply(function(){
scope.$parent[attrs.visible] = true;
});
});
$(element).on('hidden.bs.modal', function(){
scope.$apply(function(){
scope.$parent[attrs.visible] = false;
});
});
}
};
})
更新2:我进一步测试了在切换功能中添加警报的代码。变量实际上被切换为true,但模式框不会出现。您可以使用ng annotate,您可以在此处找到: 以下是关于如何使用ng annotate的两个教程:
在相同的模式下有相同的问题。
在我的例子中,在构建/缩小过程中,在html中替换了模态元素上的“可见”属性赋值,因此没有将“可见”属性传递给指令。
在构建/缩小之前:
<modal title="my title here" visible="showModal"></modal>
<modal title="my title here" visible></modal>
构建/缩小后:
<modal title="my title here" visible="showModal"></modal>
<modal title="my title here" visible></modal>
为了解决这个问题,我只是将元素和链接函数中的“可见”属性名称改成了其他名称,它的行为符合预期。这有帮助吗?您是否了解Angular的DI机制和缩小的问题?这是有文件记录的。大家好,Nganotate是构建过程的一部分。在阅读您的评论后,我还对文件运行了ngAnnotate,但它没有应用任何更改。您好,谢谢您的回答,我已经在使用ngAnnotate了。你有没有看到Nganotate在代码中遗漏了什么?回答得很好。你救了我一天
<modal title="my title here" visible></modal>