Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.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
Javascript Angularjs typeahead输入格式化程序不';在页面加载上设置模型值时,此选项不起作用_Javascript_Angularjs_Typeahead - Fatal编程技术网

Javascript Angularjs typeahead输入格式化程序不';在页面加载上设置模型值时,此选项不起作用

Javascript Angularjs typeahead输入格式化程序不';在页面加载上设置模型值时,此选项不起作用,javascript,angularjs,typeahead,Javascript,Angularjs,Typeahead,我有一个文本框,它有一个typeahead和typeahead输入格式化程序属性,在用户开始键入时提供建议列表,并在angularjs模型中存储所选值,但在文本框中显示所选值的文本,对于axample,如果模型值设置为“jsmith”,文本框将显示“John Smith”当用户从建议列表中选择建议值时,它可以正常工作,但是当我检索现有记录并使用“ng init”触发typeahead输入格式化程序时,它会遍历代码,但不会设置文本框的显示值: HTML app.js travelApp.con

我有一个文本框,它有一个
typeahead
typeahead输入格式化程序
属性,在用户开始键入时提供建议列表,并在angularjs模型中存储所选值,但在文本框中显示所选值的文本,对于axample,如果模型值设置为“jsmith”,文本框将显示“John Smith”当用户从建议列表中选择建议值时,它可以正常工作,但是当我检索现有记录并使用“ng init”触发
typeahead输入格式化程序时,它会遍历代码,但不会设置文本框的显示值:

HTML


app.js

travelApp.controller('TypeaheadCtrl', function ($scope, $http, limitToFilter) {

    $scope.entries = [];
    $scope.activedirectory = function (empName) {
        return $http.get("api/activedirectory/GetActiveDirectoryEntries/" + empName).then(function (response) {
            $scope.entries = response.data;
            return limitToFilter(response.data, 20);
        });
    };

    $scope.formatLabel = function (model) {
        if ($scope.entries.length < 1 && model != undefined) {
            $http.get("api/activedirectory/GetActiveDirectoryEntries/" + model).success(function (data) {
                $scope.entries = data;

                for (var i = 0; i < $scope.entries.length; i++) {
                    if (model == $scope.entries[i].userId) {
                        return $scope.entries[i].fullName;
                    }
                }
            }).error(function () {
                alert('Error reading JSON file.');
            });
        }

        for (var i = 0; i < $scope.entries.length; i++) {
            if (model == $scope.entries[i].userId) {
                return $scope.entries[i].fullName;
            }
        }
    }
});
travelApp.controller('TypeaheadCtrl',函数($scope,$http,limitToFilter){
$scope.entries=[];
$scope.activedirectory=函数(empName){
返回$http.get(“api/activedirectory/GetActiveDirectoryEntries/”+empName)。然后(函数(响应){
$scope.entries=response.data;
返回限值过滤器(response.data,20);
});
};
$scope.formatLabel=函数(模型){
如果($scope.entries.length<1&&model!=未定义){
$http.get(“api/activedirectory/GetActiveDirectoryEntries/”+model).success(函数(数据){
$scope.entries=数据;
对于(变量i=0;i<$scope.entries.length;i++){
if(model==$scope.entries[i].userId){
返回$scope.entries[i].fullName;
}
}
}).错误(函数(){
警报('读取JSON文件时出错');
});
}
对于(变量i=0;i<$scope.entries.length;i++){
if(model==$scope.entries[i].userId){
返回$scope.entries[i].fullName;
}
}
}
});

请告知。

您好,您的问题有答案吗?对不起。我被调到另一个项目,从来并没有机会完成它。我被困在一个类似的问题
travelApp.controller('TypeaheadCtrl', function ($scope, $http, limitToFilter) {

    $scope.entries = [];
    $scope.activedirectory = function (empName) {
        return $http.get("api/activedirectory/GetActiveDirectoryEntries/" + empName).then(function (response) {
            $scope.entries = response.data;
            return limitToFilter(response.data, 20);
        });
    };

    $scope.formatLabel = function (model) {
        if ($scope.entries.length < 1 && model != undefined) {
            $http.get("api/activedirectory/GetActiveDirectoryEntries/" + model).success(function (data) {
                $scope.entries = data;

                for (var i = 0; i < $scope.entries.length; i++) {
                    if (model == $scope.entries[i].userId) {
                        return $scope.entries[i].fullName;
                    }
                }
            }).error(function () {
                alert('Error reading JSON file.');
            });
        }

        for (var i = 0; i < $scope.entries.length; i++) {
            if (model == $scope.entries[i].userId) {
                return $scope.entries[i].fullName;
            }
        }
    }
});