TypeError:无法读取未定义的Angular JS的属性'protocol'

时间:2014-03-12 13:05:39

标签: html angularjs

我在根据以前的下拉ID

获取服务列表时遇到错误

错误:TypeError:无法读取未定义的属性'protocol'

这是我的HTML

<table>
 <tr>
 <td>Team Member</td>
 <td>                  
 <select name="teamember" class="form-control" ng-model="members" ng-options="c.Name for c in member" ng-change="loadservices(members)"></select>
 </td>
 </tr>
 <tr>
 <td>Service</td>
 <td>
 <select name="service" class="form-control" ng-model="servicesforemp" ng-options="c.Name for c in sfe"></select></td>
 </tr>
 </table>

这是我的角度控制器

var app = angular.module('appointment', ['ngRoute']);
    function getMembers($scope, $http) {
        $scope.member = [];
        $scope.servicesforemp = [];
        $http.get('/api/servicesapi/GetEmpByBusiness')
            .then(
                function(response) {
                    $scope.member = response.data;
                    $scope.membrs = $scope.member[0];
                },
                function() {

                }
            );

        $scope.loadservices = function (members) {
            var id = members.Id;
            console.log(id);//shows correct id
        //error :function exits here
            $http.get('/api/servicesapi/GetServicesByEmployees', id)
                .then(
                    function(result) {
                        $scope.servicesforemp = result.data;
                        $scope.sfe = $scope.servicesforemp[0];
                    },
                    function() {
                        alert('Error in loading services');
                    }
                );
        };
    }

1 个答案:

答案 0 :(得分:1)

如果$http使用不当,可能会出现多种情况。在我的情况下,我发送了一个未定义的URL。

$http({
  method: "GET",
  url: obj.thisIsUndefined
}).success ....

在你的情况下@doodec是对的:

$http.get('/api/servicesapi/GetServicesByEmployees', options)

get的第二个参数应该是配置对象https://docs.angularjs.org/api/ng/service/ $ http#get