从使用角度的JS JSON文件Retreive数据 [英] Retreive data from a json file using angular js

查看:157
本文介绍了从使用角度的JS JSON文件Retreive数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的角的js。我想从一个JSON文件是在远程location.Here是我的code retreive数据。请告诉我,我缺少什么,因为我无法得到的数据。

我的视图

 <机身NG控制器='companyController为comctrl'>
    < D​​IV>
        < UL>
            <李NG重复=com在comctrl.companiesNG绑定=com.name>< /李>
        < / UL>
    < / DIV>
< /身体GT;

我的控制器

  app.controller('companyController',['$ HTTP,
    功能($ HTTP)
    {
        this.companies = [];
        $ HTTP
            获得(https://dl.dropboxusercontent.com/u/28961916/companies.json')
            .success(功能(数据)
            {
                this.companies =数据;
            });
    }
]);

JSON文件

  {
    商家:
    {
        编号:3184,
        名称:Nintoreion软私人有限公司,
        状态:私人,
        营业额:500,
        域:软件技术
    },
    {
        编号:3489,
        名称:Prandeious解决方案,
        状态:公开,
        营业额:300,
        域:软件技术,
    },
    //等等
]}


解决方案

我将与

  app.controller('companyController',['$范围,$ HTTP,
    功能($范围,$ HTTP)
    {
        $ scope.companies = [];
        $ HTTP
            获得(https://dl.dropboxusercontent.com/u/28961916/companies.json')
            .success(功能(数据)
            {
                $ scope.companies =数据;
            });
    }
]);

使用 $范围而不是这个

I am new to Angular js. I want to retreive data from a json file which is at a remote location.Here's my code. Please tell me what am I missing as I am unable to get the data.

My View

<body ng-controller='companyController as comctrl'>
    <div>
        <ul>
            <li ng-repeat="com in comctrl.companies" ng-bind="com.name"></li>
        </ul>
    </div>
</body>

My Controller

app.controller('companyController', ['$http',
    function($http) 
    {
        this.companies = [];
        $http
            .get('https://dl.dropboxusercontent.com/u/28961916/companies.json')
            .success(function(data)
            {
                this.companies=data;
            });
    }
]);

JSON File

{
    businesses: [
    {
        id: 3184,
        name: "Nintoreion Soft Pvt Ltd",
        status: 'Private',
        turnover: 500,
        domain: 'Software Technology'
    },
    {
        id: 3489,
        name: "Prandeious Solutions",
        status: 'Public',
        turnover: 300,
        domain: 'Software Technology',
    },
    // so on
]}

解决方案

I would go with

app.controller('companyController', ['$scope', '$http',
    function($scope, $http) 
    {
        $scope.companies = [];
        $http
            .get('https://dl.dropboxusercontent.com/u/28961916/companies.json')
            .success(function(data) 
            {
                $scope.companies = data;
            });
    }
]);

Use $scope instead of this.

这篇关于从使用角度的JS JSON文件Retreive数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆