在json-server上运行时,角度代码可以正常工作,也就是说,可以提供来自db.json的dishs数组的数据。 但是,与NodeJS集成后,就无法提供数据了(从MongoDB到前端)。 我非常确定这两个代码是正确的并且彼此兼容,因为以前的机器上使用的相同代码正常工作。 现在,突然之间,即使该机器上的代码也显示了相同的问题。 在运行代码的机器上,我已断开MongoDB数据库的连接,而没有停止快速服务器代码,因此一切就如现在一样。
集成问题在我发现问题的另一台计算机上也是一致的。
在浏览器的控制台上检查代码时,“ ng-src”(可能还有其他功能)不可见,如果有提示的话。
以下是我的代码:-视图(AngularJS):-
<div ng-controller="HomeController">
<div class="row">
<div class="col-xs-12 col-sm-offset-1 col-sm-3">
<div class="media">
<div class="media-top media-middle">
<a ui-sref="#">
<img class="media-object img-thumbnail" ng-src="{{dish.image}}" alt="MENU" >
</a>
<div class="media-body">
<h2 class="media-heading" style="color:red">This is Hot/Featured</h2>
</div>
</div>
</div>
</div>
</div>
控制器(AngularJS):-
.controller('HomeController', ['$scope', 'menuFactory', function($scope, menuFactory) {
menuFactory.getDishes().query(
function(response) {
var dishes = response;
$scope.dish= dishes[0];
},
function(response) {
$scope.message='Error' + response.status+ " " + response.statusText;
});
}])
.controller('HomeController', ['$scope', 'menuFactory', function($scope, menuFactory) {
menuFactory.getDishes().query(
function(response) {
var dishes = response;
$scope.dish= dishes[0];
},
function(response) {
$scope.message='Error' + response.status+ " " + response.statusText;
});
}])
服务(AngularJS):-
.controller('HomeController', ['$scope', 'menuFactory', function($scope, menuFactory) {
menuFactory.getDishes().query(
function(response) {
var dishes = response;
$scope.dish= dishes[0];
},
function(response) {
$scope.message='Error' + response.status+ " " + response.statusText;
});
}])
.controller('HomeController', ['$scope', 'menuFactory', function($scope, menuFactory) {
menuFactory.getDishes().query(
function(response) {
var dishes = response;
$scope.dish= dishes[0];
},
function(response) {
$scope.message='Error' + response.status+ " " + response.statusText;
});
}])
有人请帮助我。
谢谢。