[SCRIPT]-HOW TO ACCESS ANGULARJS MODEL DATA FROM WITHIN AN EXTERNAL JQUERY PIECE OF SCRIPT?

ACCESS ANGULARJS MODEL DATA FROM WITHIN AN EXTERNAL JQUERY PIECE OF SCRIPT

AngularJS does not interpolate script like this. The recommended way to implement non-angular code that needs to interact with your angular application is write a custom directive.

Highlight (JS):

 angular.module("demo", [])
    // omitted for brevity
    .directive('fancyClass', function() {
      return {
        restrict: 'C', // directive is triggered via a class name called fancy-class
        scope: {
          'brand': '&' // lets us use an attribute named brand to declare the scope value containing the value we want
        },
        link: function(scope, element, attrs) {
          // initializes the jQuery plugin, using the scope value for brand
          element.chatter({
            hostname: 'http://www.domain.com',
            group: 'moustache',
            brand: scope.brand()
          });
        }
      }
    });

Using it on a tag in your view:

<span class="fancy-class" brand="fancyValue">Fancy 1</span>
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments