Angularjs TypeError:无法设置未定义的角度类型的属性“highlight”
我正在尝试向我的应用程序添加搜索建议,并从中获取帮助 这是app.js文件的代码:Angularjs TypeError:无法设置未定义的角度类型的属性“highlight”,angularjs,Angularjs,我正在尝试向我的应用程序添加搜索建议,并从中获取帮助 这是app.js文件的代码: var myApp = angular.module('myApp', ['ngRoute','siyfion.sfTypeahead']); myApp.factory('websitesSvc',function($http, $log, $q) { return { getwebsites: function(){ //Create a promise using promise
var myApp = angular.module('myApp', ['ngRoute','siyfion.sfTypeahead']);
myApp.factory('websitesSvc',function($http, $log, $q) {
return {
getwebsites: function(){
//Create a promise using promise library
var deferred = $q.defer();
$http({method: 'GET', url: '/api/websites/'}).
success(function(data, status, headers,config){
deferred.resolve(data);
}).
error(function(data, status, headers,config){
deferred.reject(status);
});
return deferred.promise;
}
};
});
myApp.controller('MyCtrl', ['$scope','websitesSvc','$timeout',
function($scope,websitesSvc,$timeout) {
$scope.searchString=null;
websitesSvc.getwebsites().then(function(websites){
$scope.websites = websites;
});
$timeout(function() {
var websites = new Bloodhound({
datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.domain_name); },
queryTokenizer: Bloodhound.tokenizers.whitespace,
local:$scope.websites,
});
// initialize the bloodhound suggestion engine
websites.initialize();
$scope.numbersDataset = {
displayKey: 'domain_name',
source: websites.ttAdapter()
};
// Typeahead options object
$scope.exampleOptions = {
highlight: true
};
},1000);
}
]);
添加延迟,以便首先执行服务,然后将获取的数据传递给typeahead以获得搜索建议。
如何更改代码以调试此功能?尝试删除$timeoutfunction{然后超时函数中的代码将在websitesSvc.getwebsites.thenfunctionwebsites{$scope.websites=websites;}我不知道你是不是在一个摘要循环中初始化了所有的东西?我是angular的初学者,所以你能建议我如何编辑它吗?可能是这样的: