我正在尝试使用diff2html和var jq = $.noConflict();
我创建了一个 Angular 常量来保存 jQuery,并将其传递给指令,如下所示:
应用程序.js
(function () { //IIFE to enable strict mode
'use strict';
angular.module('dashboard', ['ui.router', 'ngSanitize'])
.config(['$interpolateProvider', function ($interpolateProvider) {
$interpolateProvider.startSymbol('[[[').endSymbol(']]]');
}])
.constant('jQuery', window.jQuery);
})();
指令.js
(function () { //IIFE to enable strict mode
'use strict';
angular.module('dashboard')
.directive("loadDiff", ['$http', 'jQuery', function($http, $) {
return {
restrict: "A",
link: function(scope, elem, attrs) {
$http.get("diff url here").success(function (data) {
var diff2htmlUi = new Diff2HtmlUI({diff: data});
diff2htmlUi.draw('#line-by-line');
});
}
}
}]);
})();
问题
当它运行时,我收到以下错误:
TypeError: $ is not a function at Diff2HtmlUI._initSelection at new Diff2HtmlUI
调试这个你可以看到当Diff2HtmlUI
被实例化时它会尝试设置主体,这可能由于与var jq = $.noConflict();
.
Diff2HtmlUI.prototype._initSelection = function() {
var body = $('body');
var that = this;
我该如何解决这个问题?我希望通过 jQuery$
来覆盖 noconflict 冲突?