最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Accessing LinkedIn API from AngularJS - Stack Overflow

programmeradmin2浏览0评论

I am building an app with Angular.js accesing the LinkedIn API. What happens is that when I do a call to the API, the model does not get refreshed inmediately, but after I do another change on the screen. For example, I have binded the API call to a button, but I have to press it twice for the screen to get the data refreshed. This is my controller:

    angbootApp.controller('AppCtrl', function AppCtrl($scope, $http) {
        $scope.getCommitData = function() {
            IN.API.Profile("me").fields(
                    [ "id", "firstName", "lastName", "pictureUrl",
                            "publicProfileUrl" ]).result(function(result) {
                //set the model
                $scope.jsondata = result.values[0];
            }).error(function(err) {
                $scope.error = err;
            });
        };
    });

And this is my button and a link with the content:

<div>
  <a href="{{jsondata.publicProfileUrl}}">{{jsondata.firstName}}</a>
  <form ng-submit="getCommitData()">
    <input type="submit" value="Get Data">
  </form>
</div>

EDIT: Explanation on how I did it here

I am building an app with Angular.js accesing the LinkedIn API. What happens is that when I do a call to the API, the model does not get refreshed inmediately, but after I do another change on the screen. For example, I have binded the API call to a button, but I have to press it twice for the screen to get the data refreshed. This is my controller:

    angbootApp.controller('AppCtrl', function AppCtrl($scope, $http) {
        $scope.getCommitData = function() {
            IN.API.Profile("me").fields(
                    [ "id", "firstName", "lastName", "pictureUrl",
                            "publicProfileUrl" ]).result(function(result) {
                //set the model
                $scope.jsondata = result.values[0];
            }).error(function(err) {
                $scope.error = err;
            });
        };
    });

And this is my button and a link with the content:

<div>
  <a href="{{jsondata.publicProfileUrl}}">{{jsondata.firstName}}</a>
  <form ng-submit="getCommitData()">
    <input type="submit" value="Get Data">
  </form>
</div>

EDIT: Explanation on how I did it here

Share Improve this question edited Sep 29, 2013 at 14:32 Eugenio Cuevas asked Jan 31, 2013 at 11:03 Eugenio CuevasEugenio Cuevas 11.1k3 gold badges31 silver badges51 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You need to call $scope.$apply when retrieving the results/error

angbootApp.controller('AppCtrl', function AppCtrl($scope, $http) {
    $scope.getCommitData = function() {
        IN.API.Profile("me").fields(
                [ "id", "firstName", "lastName", "pictureUrl",
                        "publicProfileUrl" ]).result(function(result) {
            //set the model
            $scope.$apply(function() {
                $scope.jsondata = result.values[0];
            });
        }).error(function(err) {
            $scope.$apply(function() {
                $scope.error = err;
            });
        });
    };
});

Anything outside angular world does not trigger automatic refresh of the views. See $apply

发布评论

评论列表(0)

  1. 暂无评论