Angularjs指令类型错误:对象不是函数
我是新来安格拉斯的。。。为了让它工作,我很生气:Angularjs指令类型错误:对象不是函数,angularjs,angularjs-directive,Angularjs,Angularjs Directive,我是新来安格拉斯的。。。为了让它工作,我很生气: angular.module('app', ['ui.select2']).directive("selectCompany", function($timeout) { return { restrict: 'A', replace: true, template: '<input type="text" name="company_id" ng-model="companySel
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; },
}));
},
};
});
angular.module('app',['ui.select2'])指令(“selectCompany”,函数($timeout){
返回{
限制:“A”,
替换:正确,
模板:“”,
作用域:{},
链接:函数(范围、元素、属性、ctrl){
$timeout(element.select2({
占位符:“客车公司”,最小计算长度:3,允许清除:真,
阿贾克斯:{
url:'http://'+window.location.host+'/ajax/module/company/load companys',
数据类型:“json”,
键入:“post”,
基特米利斯:“250”,
数据:函数(term,page){return{name:term};},
结果:函数(数据,页面){return{results:data};}
},
formatResult:函数(项){return item.name;},
formatSelection:函数(项){return item.name;},
转义标记:函数(m){return m;},
}));
},
};
});
这是我的Angular指令,它将
转换为select2控件。它目前可以工作,它还返回详细信息,但我得到了以下错误:
有什么想法吗?通常,您希望在开发过程中使用非精简版本的脚本,因为它们提供了更多描述性的堆栈跟踪 很难说到底发生了什么,但请尝试:
$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;
},
})
});
谢谢!!我想您刚刚在$timeout中添加了函数(),对吗?。它工作得很好。顺便说一句,我习惯于内联1行函数以使代码更干净(对我来说;))当我复制粘贴它时,它被弄乱了,所以我不得不通过一个美化器运行:)