Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular.js+;require.js+;jQuery插件自定义指令_Javascript_Jquery_Angularjs_Twitter Bootstrap - Fatal编程技术网

Javascript Angular.js+;require.js+;jQuery插件自定义指令

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:

我是Angular and Require的新手,我的问题是关于以下代码(我已经连接了Angular and Require,如果需要,我可以包括文件);未初始化引导开关元素:

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) {