",angularjs,angular-routing,ngroute"/>

首页 > 解决方案 > TypeError:无法在 angular.min.js:62 处读取 f (angular.min.js:62) 处未定义的属性 'childNodes'

"

问题描述

我很长时间以来一直面临这个问题,当我尝试使用{{}}. 我用于ngRoute在不同页面之间进行路由。ng-model当我尝试将数据绑定到变量或HTML 中时,会发生上述错误。

但是当模型的值已经在控制器中声明时它工作正常。

我收到的数据来自一个自定义服务,它最终在从控制器调用它时发出一个 http GET 请求。

<html ng-app="bgpsApp">
<body>
    <div ng-view></div>
</body>
<!-- scripts loaded in a sequence: 
     jquery, angular.js(1.6.9), angular-route.js,  app.js, customservices.js -->
</html>

应用程序.js

var bgpsapp = angular.module('bgpsApp', ['ngRoute']);
bgpsapp.config(function($routeProvider) {
  $routeProvider
    .when('/', {
      templateUrl: 'brahmagpslogin.html'
    })
    .when('/portal', {
      resolve: {
        "check": function($location, $rootScope) {
          if (!$rootScope.logStatus) {
            $location.path('/');
          }
        }
      },
      templateUrl: 'portal.html'
    })
    .otherwise({
      redirectTo: '/'
    })
})

bgpsapp.controller('MainController', ['$scope', '$rootScope', '$http', 'services', function($scope, $rootScope, $http, services) {
  services.getDashboardData($rootScope.master.userId).then(function(response) {
    $scope.vehiclesStatus = response.data.data.vehiclesStatus;
    console.log($scope.vehiclesStatus); 
    // ** assigning value to bind **
    $scope.vehicleCount = $scope.vehiclesStatus.vehicleCount;
  }, function(response) {
    alert(response.data.message);
  });
}]);

门户网站.html

<div id="wrapper" ng-controller="MainController">
  <div class="row">
    <div class="col-xs-12 col-sm-12 col-md-7 col-lg-7">
      <h4>Vehicles
        <small> Status</small>
      </h4>
    </div>
    <div class="col-xs-12 col-sm-12 col-md-5 col-lg-5">
      <h4>
        <!-- trying to bind data to this variable -->
        {{vehicleCount}}
        <small>Trucks</small>
      </h4>
    </div>
  </div>
</div>

自定义服务js

bgpsapp.service('services', function($http) {
  this.baseURL = "http://xxx/api/data";
  this.getDashboardData = function(customerId) {
    var d_response = {};
    var response = $http.get(this.baseURL + "/customer/data/dashboard?userId=" + customerId);

    return response;
  }
});

标签: angularjsangular-routingngroute

解决方案


推荐阅读