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 9244611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:04:43+00:00 2026-06-18T09:04:43+00:00

Angular newbie here. I am trying to figure out what’s going wrong while passing

  • 0

Angular newbie here. I am trying to figure out what’s going wrong while passing objects to directives.

here’s my directive:

app.directive('walkmap', function() { 
  return {
    restrict: 'A',
    transclude: true,
    scope: { walks: '=walkmap' },
    template: '<div id="map_canvas"></div>',
    link: function(scope, element, attrs)
    {
      console.log(scope);
      console.log(scope.walks);
    }
  };
});

and this is the template where I call the directive:

<div walkmap="store.walks"></div>

store.walks is an array of objects.

When I run this, scope.walks logs as undefined while scope logs fine as an Scope and even has a walks child with all the data that I am looking for.

I am not sure what I am doing wrong here because this exact method has worked previously for me.

EDIT:

I’ve created a plunker with all the required code: http://plnkr.co/edit/uJCxrG

As you can see the {{walks}} is available in the scope but I need to access it in the link function where it is still logging as undefined.

  • 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-18T09:04:44+00:00Added an answer on June 18, 2026 at 9:04 am

    Since you are using $resource to obtain your data, the directive’s link function is running before the data is available (because the results from $resource are asynchronous), so the first time in the link function scope.walks will be empty/undefined. Since your directive template contains {{}}s, Angular sets up a $watch on walks, so when the $resource populates the data, the $watch triggers and the display updates. This also explains why you see the walks data in the console — by the time you click the link to expand the scope, the data is populated.

    To solve your issue, in your link function $watch to know when the data is available:

    scope.$watch('walks', function(walks) {
       console.log(scope.walks, walks);
    })
    

    In your production code, just guard against it being undefined:

    scope.$watch('walks', function(walks) {
      if(walks) { ... }
    })
    

    Update: If you are using a version of Angular where $resource supports promises, see also @sawe’s answer.

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

Sidebar

Related Questions

Angular newbie here. Trying to wrap my head around directives, scopes, transclusions, and what
The app runs but Angular data objects are not recognized. Here is the JavaScript
Angular.js uses several directives prefixed with ng like below: ng (base directive) ng-switch ng-repeat
I'm trying to do inline editing in a form with an Angular directive, unfortunately
How do I access hidden fields in angular? I have an app, where I
I'd like to use socketstream's RPC over websockets abstraction while using Angular for MVC.
I'm newbie in angularJS world and I probably misunderstand something. My app use controllers,
Sample app: http://angular.github.com/angular-phonecat/step-11/app/#/phones If you choose the last phone Motorola charm it will show
I have an angular app with a few routes. on one of them there
I'm trying to add two angular apps / modules to one page. In the

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.