gpt4 book ai didi

javascript - Angular.js + require.js + jQuery 插件自定义指令

转载 作者:行者123 更新时间:2023-11-29 21:56:26 25 4
gpt4 key购买 nike

我是 Angular 和 Require 的新手,我的问题是关于以下代码(我已经连接了 angular 和 require,如果被问到我可以包含文件); bootstrap-switch 元素未被初始化:

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(我知道路径正在工作,我确定我在某个地方遇到了语法问题。如果没有,请详细说明。我们将不胜感激!!!!

谢谢!!!

最佳答案

语法问题1:

改变:

define(['myapp.ui/module', function (module) {

收件人:

define(['myapp.ui/module'], function (module) {

此外,请考虑使用与“模块”不同的参数名称,因为它可能会与 AMD 模块混淆。 (名为'module'的模块是一个特殊模块,指的是加载模块本身。)

语法问题2:

第二个return 语句不会做任何事情。也许您想在外部 define 中包含所有依赖项:

define([
'myapp.ui/module',
'myapp.ui/switch/bootstrap-switch.min',
'css!myapp.ui/switch/bootstrap-switch.min'
], function (ui) {

关于javascript - Angular.js + require.js + jQuery 插件自定义指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26308994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com