Angularjs指令类型错误:对象不是一个函数 [英] Angularjs directive TypeError: object is not a function

查看:219
本文介绍了Angularjs指令类型错误:对象不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的Angularjs ...只是生气了,使这一工作:

I'm new at Angularjs... Just got mad making this to work:

angular.module('app', ['ui.select2']).directive("selectCompany", function($timeout) {

    return {
        restrict: 'A',
        replace: true,
        template: '<input type="text" name="company_id" ng-model="companySelected" />',
        scope: {},

        link: function (scope, element, attrs, ctrl) {
            $timeout(element.select2({
                placeholder         : "Buscar empresa", minimumInputLength : 3, allowClear : true,
                ajax: {
                    url                 : 'http://' + window.location.host + '/ajax/module/company/load-companies',
                    dataType            : 'json',
                    type                : 'post',
                    quietMillis         : '250',
                    data                : function (term, page) { return { name: term }; },
                    results             : function (data, page) { return { results : data }; }
                },
                formatResult    : function(item) { return item.name; },
                formatSelection : function(item) { return item.name; },
                escapeMarkup    : function (m) { return m; },
            }));
        },
    };
});

这是我的角度指令,这使得&LT; D​​IV选择-公司&GT;&LT; / DIV&GT; 成SELECT2控制。它工作在此刻,它也会返回的细节,但我得到这个错误:

This is my Angular directive which makes a <div select-company></div> into a select2 control. It works at the moment, it also return the details but I'm getting this error:

任何想法?

推荐答案

通常情况下,你会希望与开发过程中的脚本不缩小的版本一起使用,因为他们给更多的描述堆栈跟踪...

Normally, you'd want to work with non-minified versions of scripts during development, because they give more descriptive stack traces...

很难说究竟是怎么回事,但尝试:

Hard to say what exactly is going on here, but try:

$timeout(function () {
  element.select2({
    placeholder: "Buscar empresa",
    minimumInputLength: 3,
    allowClear: true,
    ajax: {
      url: 'http://' + window.location.host + '/ajax/module/company/load-companies',
      dataType: 'json',
      type: 'post',
      quietMillis: '250',
      data: function (term, page) {
        return {
          name: term
        };
      },
      results: function (data, page) {
        return {
          results: data
        };
      }
    },
    formatResult: function (item) {
      return item.name;
    },
    formatSelection: function (item) {
      return item.name;
    },
    escapeMarkup: function (m) {
      return m;
    },
  })
});

这篇关于Angularjs指令类型错误:对象不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆