我买了metronic管理模板并试图在角度2中使用它,但是我有两个JS文件出错:app.js
和layout.js
。不能从一个js调用函数到第二个函数
app.js
内容:
var test = function() {
/* ... */
return {
init: function(){ /* ... */ },
getResponsiveBreakpoint: function(size) {
// bootstrap responsive breakpoints
var sizes = {
'xs': 480, // extra small
'sm': 768, // small
'md': 992, // medium
'lg': 1200 // large
};
return sizes[size] ? sizes[size] : 0;
}
}
}();
jQuery(document).ready(function() {
test.init(); // init metronic core componets
});
layout.js
内容:
var Layout = function() {
var resBreakpointMd = test.getResponsiveBreakpoint('md');
/* ... */
return {
init: function() { /* ... */ }
}
}();
$(document).ready(function() {
Layout.init(); // init metronic core componets
});
layout.js
返回此错误:
test.getResponsiveBreakpoint is not a function
但如果我写test.getResponsiveBreakpoint('md');
之外布局的功能,它的工作原理。
console.log(test.getResponsiveBreakpoint('md'));
var Layout = function() {/* ... */}
如果console.log正常工作,那么您的浏览器正在欺骗您:v –
当然,它会失败,因为'test.getResponsiveBreakpoint'还不是一个函数。它不会像当前的布局结构一样。 – dfsq
你是如何加载js文件的? – PierreDuc