首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Node/Angular,如何调用api (使用节点模块中的方法)并将数据发送到作用域?

使用Node/Angular,如何调用api (使用节点模块中的方法)并将数据发送到作用域?
EN

Stack Overflow用户
提问于 2015-09-22 01:00:50
回答 1查看 52关注 0票数 0

我正在尝试使用angular +节点,并对JS Api进行方法调用。它返回我的index.js文件中的数据,我希望这些数据在我的angular模块中可用,以便附加到$scope。

我的两个方法/尝试是:

1)将hiw-api模块作为工厂参数注入(不会工作/how do不会获取我的模块。2)使用RequireJS包含节点模块hiw-api (太复杂)

我的目标是,一旦数据在$scope中,我就可以对其进行操作,但我似乎无法将其放在那里。任何帮助都将不胜感激!index.js Githubindex.html (如果你敢)

代码语言:javascript
复制
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);

    });

};
EN

回答 1

Stack Overflow用户

发布于 2015-09-22 02:16:48

假设您正确地将HIWmethods定义为服务,则必须将其注入到控制器中,如下所示:

代码语言:javascript
复制
.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;
            });

    }]);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32700766

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档