Recover data from a json file using js angular

advertisements

Using Angular js, I want to retrieve 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
]}


this doesn't refer to the controller in the callback. Try...

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

The JSON is also invalid (properties need to be in double quotes). Use something like http://jsonlint.com/ to validate it.