Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs TypeError:无法设置未定义的角度类型的属性“highlight”_Angularjs - Fatal编程技术网

Angularjs TypeError:无法设置未定义的角度类型的属性“highlight”

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

我正在尝试向我的应用程序添加搜索建议,并从中获取帮助

这是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 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的初学者,所以你能建议我如何编辑它吗?可能是这样的: