我发现了许多类似的问题,但我无法将解决方案应用于我的问题。
因此,在我的angular应用程序中,我正在绘制nvd3图表。
我正在服务中执行get请求,并且我可以从浏览器中的网络中看到,我总是按照预期获得图表数据。
问题是,当我运行grunt serve启动我的angular应用程序时,我仍然通过api获取数据,但由于某种原因,它们没有显示出来。
这种情况只有在我运行grunt serve时才会发生。但是,如果我点击刷新,在运行grunt serve之后,数据可以正确显示。
提前感谢您的帮助。
这就是我想要做的:
'use strict';
angular.module('myApp')
.service('mainService', function($http) {
this.getData = function() {
return $http({
method: 'GET',
url: '/rest/api/config',
});
}
})
.controller('MainCtrl', function($scope, $http, mainService) {
var name = 'main';
var model;
mainService.getData().then(function(d) {
model = d.data;
$scope.modelling();
});
$scope.modelling = function() {
if(!model) {
console.log("no model");
// set default model for demo purposes
model = {
title: "about",
structure: "12/4-4-4",
};
}
console.log(model);
$scope.name = name;
$scope.model = model;
$scope.collapsible = true;
}
});发布于 2014-09-18 21:31:16
试试这样的东西。最初,在您的示例中,$scope.model将是未定义的。
.controller('MainCtrl', function($scope, $http, mainService) {
var name = 'main';
mainService.getData().then(function(d) {
$scope.modelling(d.data);
});
$scope.modelling = function(data) {
//do something with data here, or set
$scope.model = data;
}
$scope.name = name;
$scope.collapsible = true;
}
});
That might work, depends on how you set up the nvd3 charts.https://stackoverflow.com/questions/25912199
复制相似问题