angularjs - 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;
}
});
解决方案
推荐阅读
- java - 如何使用 Gradle 正确生成 R 文件,而我只将资源放在 src/test 下
- sql - 仅对 SQL Server 中具有值的行进行分组
- opencv - 设置用于图像捕获和图像处理的场景
- python-3.x - 服务器(Ubuntu 16.04)在运行 LSTM 时冻结并停止响应
- rust - 语法是什么:`instance.method::
()`? - c# - 无法将属性或索引器“AuthenticationHeaderValue.Parameter”分配给 - 它是只读的
- kubernetes - GKE Ingress - 简单的 nginx 示例但出现错误“找不到后端的节点端口”
- c++ - 如何防止vector改变内存地址
- python - Django 和 ElasticBeanstalk:内部服务器错误,HTTP/2 协议将处于非活动状态
- javascript - 在 Javascript 书签中设置下拉值,我的代码仅适用于文本字段