Javascript Angular.js+;require.js+;jQuery插件自定义指令
我是Angular and Require的新手,我的问题是关于以下代码(我已经连接了Angular and Require,如果需要,我可以包括文件);未初始化引导开关元素:Javascript Angular.js+;require.js+;jQuery插件自定义指令,javascript,jquery,angularjs,twitter-bootstrap,Javascript,Jquery,Angularjs,Twitter Bootstrap,我是Angular and Require的新手,我的问题是关于以下代码(我已经连接了Angular and Require,如果需要,我可以包括文件);未初始化引导开关元素: define(['myapp.ui/module', function (module) { module.directive('bootstrapSwitch', ['$parse', '$path', function ($parse, $path) { return { restrict:
define(['myapp.ui/module', function (module) {
module.directive('bootstrapSwitch', ['$parse', '$path', function ($parse, $path) {
return {
restrict: 'A',
replace: true,
link: function (scope, element) {
//load requirements for this directive.
console.log(element.bootstrapSwitch);
element.bootstrapSwitch();
}
};
return require([
'myapp.ui/switch/bootstrap-switch.min',
'css!myapp.ui/switch/bootstrap-switch.min'],
function () {
return {
restrict: 'A',
replace: false,
link: function (scope, element) {
//load requirements for this directive.
element.bootstrapSwitch();
}
};
});
}]);
}]))
我可以看到正在加载的指令文件(上面的一个),但是元素没有初始化,我看不到bootstrap-switch.min.css和bootstrap-switch.min.js(我知道路径在工作,我肯定我在某个地方遇到了sintax问题。如果没有,请详细说明。任何帮助都将不胜感激
谢谢!!!无法在return语句之后返回其他内容。如果require语句试图加载某些依赖项,可以将其放入define first参数中。语法问题1: 更改:
define(['myapp.ui/module', function (module) {
致:
也可以考虑使用一个不同的参数名称,因为它可以与AMD模块混淆。(称为“模块”的模块是指加载模块本身的一个特殊模块。 语法问题2:
第二个return
语句将不起任何作用。可能您希望在外部define
中包含所有依赖项:
define([
'myapp.ui/module',
'myapp.ui/switch/bootstrap-switch.min',
'css!myapp.ui/switch/bootstrap-switch.min'
], function (ui) {
如:定义(['myapp.ui/module','myapp.ui/switch/bootstrap switch.min',..)等?
define([
'myapp.ui/module',
'myapp.ui/switch/bootstrap-switch.min',
'css!myapp.ui/switch/bootstrap-switch.min'
], function (ui) {