我正在努力使我的angularjs项目丑化。丑化过程后出现问题。以下功能无效。
app.factory('Showmenusheet', function($rootScope){
return {
//Custom pop up sheet for activities completed notification
openNativePopup: function(imageUrl, title, para, buttonText, buttonLink){
$('#popupTitle').html(title);
$('#popupPara').html(para);
$('#popupButton').html(buttonText);
var imageElement = angular.element(document.querySelector('#popupImage'));
var goToButton = angular.element(document.querySelector('#goToButton'));
var closeButton = angular.element(document.querySelector('#closeButton'));
goToButton.removeAttr("ng-show");
closeButton.removeAttr("ng-show");
goToButton.removeAttr("go-click");
if(buttonLink == false) {
goToButton.attr("ng-show", false);
closeButton.attr("ng-show", true);
$('#closeButton').html(buttonText);
} else {
goToButton.attr("ng-show", true);
goToButton.attr("go-click", buttonLink);
closeButton.attr("ng-show", false);
$('#goToButton').html(buttonText);
}
imageElement.attr("src", 'assets/images/app_icons/'+imageUrl);
compile(goToButton);
compile(closeButton);
compile(imageElement);
setTimeout(function(){$('#nativePopup').addClass("showNativePopup");},350);
setTimeout(function(){$('#deletemenu').addClass('delete-menu-active');},0);
}
}
});
所以基本上,如果我不丑化代码,则弹出功能可以正常工作而没有任何问题,但是在丑化之后,我在上面的屏幕截图中得到了错误。我在上述功能中是否做错了标准?
编辑添加了各种控制台日志测试后,我发现控件显示compile()
函数错误。我希望每次从AngularJS调用'openNativePopup'函数时,编译函数都会更新HTML。可以使用什么替代方法代替compile()?
[
angular
.module('MyModule', [])
.service('myService', function($rootScope) {
$rootScope.title = 'my title';
});
角度将$rootScope
注入您的函数。只要此代码经过压缩,它就会变成类似的东西
angular .module('MyModule', []) .service('myService', function(a) { a.title = 'my title'; });
这使AngularJS依赖项注入机制抛出,导致没有这样的a
注册到angular。为了解决此问题,有$inject Property Annotation。
因此,该代码应看起来像这样以支持最小化。
angular .module('MyModule', []) .service('myService', ['$rootScope', function($rootScope) { $rootScope.title = 'my title'; }]);
[有一个工具可以执行此annotation automatically