jeudi 7 janvier 2016

AngularJS Widget/Plugin via Directive

I'm working on a relatively small web portal running on top of Angular. I'm still an Angular greenhorn, though I've managed to wrap my mind around the more important concepts.

In any event, I was creating a small widget/plugin for GitHub data retrieval. This is my code,

ng-github.js

(function() {

  angular.module('ng-github', [])
    .run(function() {
      console.log('module instantiated');
    })
    .directive('git-user', function($http) {
      return function(scope, element, attr) {
        console.log('invoked');
        $http.get('http://ift.tt/1gcW4Wp' + attr['gitUser'])
          .success(function(data) {
            scope.gUser = data;
          })
          .error(function(data, status) {
            console.error('Github User Request Error', status, data);
          })
      };
    })

})();

view.html

...

<span gitUser="neetVeritas" ng-bind="gUser.following"></span>

...

The module is being instantiated, as I'm getting a response from the .run(...) function, but the directive's link function is not being invoked. I've included the ng-github module in my main application, and I'm not receiving any angular-js related errors, so I'm stumped here. Any ideas?




Aucun commentaire:

Enregistrer un commentaire