我试图使用diff2html和var jq = $.noConflict();
与noconflict
我创建了一个角度不变持有jQuery和我通过它进入指令格式化角指令内部差异的角度指令内运行的jQuery插件diff2html像这样:
app.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);
})();
directive.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冲突?
附加的jquery,删除此恒定原因它是无用的。 Defininf函数($ http,$)很有趣,但没有做任何事情...... –
@PetrAveryanov jQuery已被定义为第一个包含。这个答案是建议在这里:https://stackoverflow.com/questions/34402898/pass-jquery-dependency-to-angular-js-controller – Dan
看到这个演示,我不能重现该错误:http://plnkr.co/编辑/ hLnuvQ9kHRRdsaHYK3SS?p =预览 –