0

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('https://api.github.com/users/' + 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?

1
  • 1
    You have the mixed the casing of the names: do module(...).directive('gitUser', ...) and use it as <span git-user="...">. I.e.: directive definition in code: camelCase, directive usage in HTML: dash-case. Commented Jan 7, 2016 at 23:18

1 Answer 1

2

Looks to me as if you have the naming of the directive backwards. Shouldn't the name be camelcase (i.e. gitUser) in the directive declaration and hyphenated in the html?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.