【问题标题】:Angular materializecss select directive gives me errorAngular materializecss 选择指令给了我错误
【发布时间】:2015-11-22 22:03:31
【问题描述】:

我尝试包含 http://krescruz.github.io/angular-materialize/#select,但我在控制台中遇到错误(您可以在图像中看到)。这个问题有什么解决方案吗,这里是angular-materialize.js中的指令

angular.module("ui.materialize.material_select", [])
        .directive("materialSelect", ["$compile", "$timeout", function ($compile, $timeout) {
            return {
                link: function (scope, element, attrs) {
                    if (element.is("select")) {
                        $compile(element.contents())(scope);
                        function initSelect() {
                            element.siblings(".caret").remove();
                            element.material_select();
                        }
                        $timeout(initSelect);
                        if (attrs.ngModel) {
                            scope.$watch(attrs.ngModel, initSelect);
                        }
                        if ("watch" in attrs) {
                            scope.$watch(function () {
                                return element[0].innerHTML;
                            }, function (oldVal, newVal) {
                                if (oldVal !== newVal) {
                                    $timeout(initSelect);
                                }
                            });
                        }
                    }
                }
            };
        }]);

【问题讨论】:

  • 错误很明显:element.is is not a function..如果使用jQuery方法,只需加载jQuery即可。

标签: angularjs materialize


【解决方案1】:

这个错误意味着你试图在不加载 jQuery 的情况下使用 jQuery 方法。 Angular 带有类似 jQuery 的轻量级实现 (angular.element),但方法集有限。这些方法不包括istrigger(以及许多其他方法)。

所以解决方案很简单:如果您使用 jQuery 方法 - 在 Angular 之前加载 jQuery。

【讨论】:

  • 好的,如果我在 Angular 之前加载 jquery,选择就可以工作,但是那个选择不会返回我的值。您可以在 github 上看到 jquery 是在 angular 之后加载的,并且一切正常
猜你喜欢
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-29
  • 2017-02-02
  • 2017-06-11
  • 2016-03-04
相关资源
最近更新 更多