我正在尝试使用angular +节点,并对JS Api进行方法调用。它返回我的index.js文件中的数据,我希望这些数据在我的angular模块中可用,以便附加到$scope。
我的两个方法/尝试是:
1)将hiw-api模块作为工厂参数注入(不会工作/how do不会获取我的模块。2)使用RequireJS包含节点模块hiw-api (太复杂)
我的目标是,一旦数据在$scope中,我就可以对其进行操作,但我似乎无法将其放在那里。任何帮助都将不胜感激!index.js Github,index.html (如果你敢)
var hiw = require("hiw-api");
var apiKey = "da45e11d07eb4ec8950afe79a0d76feb";
var api = new hiw.API(apiKey);
var http = require("http");
exports.index2 = function (req, res) {
var rawresponse;
var founderror;
var indicatorDescription;
var locales;
//var allinidcatorsURL = '/Indicators/ { page }?Key= { key }';
//var filter = new hiw.Filter()
// .addEqual(hiw.Locale.Fields.ScriptFullName, "Arkansas");
hiw.Synchronizer.sync([
hiw.IndicatorDescription.getByID(279, api, function (data, response, error) {
indicatorDescription = data;
console.log(indicatorDescription.fullDescription);
console.log(indicatorDescription);
title = "Express"; //response: rawresponse, error: founderror
}),
hiw.Locale.getAll(api, function (data, response, error) {
locales = data; //Array of Locale
//console.log(locales);
})
], function (data) {
res.sendfile('./views/index.html');
//res.json(locales);
});
};发布于 2015-09-22 02:16:48
假设您正确地将HIWmethods定义为服务,则必须将其注入到控制器中,如下所示:
.controller('mainController', ['$scope', 'HIWmethods', function($scope, HIWmethods) {
$scope.formData = {};
$scope.loading = true;
// GET =====================================================================
// when landing on the page, get all todos and show them
// use the service to get all the todos
$scope.test = "Hello world!!!!!!!!!!"
HIWmethods.getLocales().then(function(data) {
$scope.locales = {
availableOptions: data
}
$scope.loading = false;
});
}]);https://stackoverflow.com/questions/32700766
复制相似问题