Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9175165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:52:10+00:00 2026-06-17T16:52:10+00:00

Angular newbie here. Trying to wrap my head around directives, scopes, transclusions, and what

  • 0

Angular newbie here. Trying to wrap my head around directives, scopes, transclusions, and what not.

Here’s what I’m trying to achieve — each table in a cell needs to be color-coded (change in bgcolor OR addition of a specific CSS class) based on the value inside that cell. The complication is that the cell does not have a bare value – it has other bits & baubles along with it. Therefore, within the cell, I would like to have the ability to add custom HTML.

Here’s what my template looks like:

<span color-codify="{'max' : object.max, 'value' : object.value}" ng-transclude>
  {{ object.value }}
  <a href="#">Edit</a> | <a href="#">Delete</a>
</span>

Here’s what my directive looks like:

myModule.directive('colorCodify', function() {
  return {
    restrict: 'A',
    transclude: 'true',
    'link' : function(scope, element, attrs, controller) {
      var opts = scope.$eval(attrs.colorCodify);
      console.log(opts); // THIS DISPLAYs {max: undefined, value: undefined} 
    }
  }
});

The surprising part is, that even though {{ object.value }} within the <span> element renders correctly, it is not being passed down to the directive properly. However, if I refer to $parent it works properly. Example:

<span color-codify="{'max' : $parent.object.max, 'value' : $parent.object.value}" ng-transclude></span>

What’s going on?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:52:11+00:00Added an answer on June 17, 2026 at 4:52 pm
    <span color-codify="{'max' : object.max, 'value' : object.value}" ng-transclude>
      {{ object.value }}
      <a href="#">Edit</a> | <a href="#">Delete</a>
    </span>
    

    .

    myModule.directive('colorCodify', function() {
      return {
        restrict: 'A',
        transclude: 'true',
        scope: {getOpts: "&colorCodify"},
        'link' : function(scope, element, attrs, controller) {
          var opts = scope.getOpts();
          console.log(opts);
        }
      }
    });
    

    For more info, check out directive definition object part in http://docs.angularjs.org/guide/directive

    Edit about $parent:

    I suppose you need to read more about how scopes work in angular (how do they inherit from one another and how do they override those inherited properties). This would be one of the most important aspects in angularjs. I suggest you to follow the links and read them again and again until you get it.

    ngScope Documentation Reference
    Developer Guide
    Bonus (video from angularjs team, discussing angularjs’ best practises):
    Youtube

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in the middle of trying to get my head around the data binding
The app runs but Angular data objects are not recognized. Here is the JavaScript
Trying to use the Angular $resource, and its coming back as not a method.
Looking through angular js tutorial , I do not understand where the repeater (function?)
I'm trying to add two angular apps / modules to one page. In the
I'm trying to do something in Angular like this: Your search found {{ searchResults.iTotalRecords
Warning: Angular newbie ahead. I have this code in an angular.js page <div class=clearfix
I want to use angular in an app except that angular is not loaded
In the angular-seed-project the filters, services, and directives are placed in different modules. Why?
I am using Cordova and Angular for a small webapp. Here is the implementation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.