1

I am passing the array to directive and getting it in directive method. but I am trying to get a index of value. but getting as undefiend. what is the issue here?

array creation :

var dataSize = gridView.baseData.length / viewPorts;
        for( var i = 0; i < dataSize; i++ ){
            gridView.pages[i] = {
                show : i ==0 ? true:false,
                pageData : gridView.baseData.splice( 0, viewPorts )
            };
        }
        return gridView.pages;

here is my directive:

var dataGridMaker = function( ) {

    return {
        scope: {
            "pages" : "="
        },
        replace: true,
        template : GridTemplate.join(''),
        link: function(  scope, element, attrs ) {
            console.log( scope.pages ); //getting all array values
            console.log( scope.pages[0] ); //undefined-why?
        }
    }

}

here is the console:

[]0: Object 1: Object 2: Object 3: Object 4: Object 5: Object 6: Object 7: Object 8: Object 9: Objectlength: 10__proto__: Array(0)
dataGridDirective.js:24 undefined
2
  • can you show scope.pages ? Commented May 15, 2017 at 5:44
  • required to post array values? Commented May 15, 2017 at 5:46

1 Answer 1

1

It may be an unresolved promise or a scope change (depends on what you are doing in the controller). Try to wrap console.log( scope.pages[0] ); in a timeout with no delay and see what happens. Something like this:

$timeout(function () {
   console.log( scope.pages[0] );
});
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.