0

Trying to get gist-embed (https://github.com/blairvanderhoof/gist-embed) working within my Angular app but with no luck.

It works no problem on my homepage (which is not part of the Angular app) but when I use something like:

<code data-gist-id="<gist-id>"></code>

within the app it won't show. There are no messages in the console to explain why though.

Could someone explain why and offer a solution?

1

4 Answers 4

1
(function($) {

  $(function() {
    // find all elements containing "data-gist-id" attribute.
    $('[data-gist-id]').each(function() {
      var $elem = $(this),
        id,

that lib is coded in such a way one cant really use it in angular,you'll have to look for a fork that offers a proper jquery plugin architecture you can use into a directive.That lib doesnt respect basic jQuery plugin architecture.

And no Error will show up because it's likely the .each will execute before your angular app runs.

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

1 Comment

As of June (version 1.8), its now a jQuery plugin.
0

As of June (version 1.8), the gist-embed project is now a jQuery plugin.

var $code = $('<code data-gist-id="474f6d7839fccffc4b2a"/>');
$code.appendTo('body').gist();

Comments

0

Basically you have to trigger "gist()" on the dom elements.

Try this, it worked for me very well.

            // register trigger gist on every template include
                $rootScope.$on('$includeContentLoaded', function() {

                    // initialize gist on new elements
                    angular.element(document).ready(function() {
                        if (typeof(angular.element(document).gist) === 'function') {
                            angular.element('[data-gist-id]').gist();
                        }
                    });
                });

I put together a small library hoping to solve the problem.

Check it out : https://github.com/pasupulaphani/angular-gist-embed

Comments

0

Chekout this angular module : https://github.com/kiran3807/another-angular-gist-embed

This allows you to include the gists in your angular project in the form of a directive, one of the attributes for which is the gist-id :

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script src="path/to/another-angular-gist-embed.js"></script>
<script>
   angular.module('example',['another-angular-gist-embed']);
   angular.module.controller('exampleCtrl',['$scope',function($scope){
       $scope.gistId = 'a85770344febb8e30935';
  }]);
</script>
</head>
</head>
<body ng-app="example">
  <div ng-controller="exampleCtrl">
    <!-- This loads a gist with a specific id-->
    <gist-embed data-gist-id="gistId"></gist-embed>
  </div>
</body>
</html>

Declaration : I am the author of this module

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.