0

我目前正在移动 AngularJS 应用程序中的代码,并开始收到有关客户指令的错误。该指令在原版中运行良好,但在我移动了一些东西后返回了下面列出的错误。

我一直在研究代码以尝试找到我错过的参考、关闭的文件版本或突然弹出此错误的任何其他原因。不幸的是,我什么也没找到。

什么可能导致 AngularJS 指令出现以下错误?

TypeError: Object [object Object] has no method 'slider'
   at link (http://localhost:8000/static/modeling/js/directives/slider.js:9:13)
   at k (http://localhost:8000/static/js/angular.min.js:44:444)
   at e (http://localhost:8000/static/js/angular.min.js:40:139)
   at e (http://localhost:8000/static/js/angular.min.js:40:156)
   at e (http://localhost:8000/static/js/angular.min.js:40:156)
   at e (http://localhost:8000/static/js/angular.min.js:40:156)
   at k (http://localhost:8000/static/js/angular.min.js:44:382)
   at e (http://localhost:8000/static/js/angular.min.js:40:139)
   at e (http://localhost:8000/static/js/angular.min.js:40:156)
   at http://localhost:8000/static/js/angular.min.js:39:205 <slider id="slider" scale="scale" class="span2 ng-isolate-scope ng-scope">

我的指令定义如下:

myApp.directive('slider', function() {
    return {
      restrict: 'E',
      scope: {
        scale: '='
      },
      link: function(scope, elm, attrs) {
        console.log(elm);
        elm.slider({  // !! THIS IS LINE 9 (per error message) !!
            min: 1,
            max: 50,
            step: 1,
            value: 30,
            slide: function(event, ui) {
                scope.scale = ui.value;
                scope.$apply();
            }
        })
      }
    }
});

使用的示例 HTML 标记是:

<slider id="slider" scale="scale" class="span2"></slider>
4

2 回答 2

2

包含的顺序很重要!正确的顺序:

<script src="js/jquery.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/angular.min.js"></script>
...
于 2014-03-24T10:41:20.847 回答
1

看起来您忘记在重新配置的应用程序中包含 jQueryUI。

于 2013-07-31T17:58:50.930 回答