0

I'm having problem when converting my jquery plugin into angular directives, here's my jquery plugin call:

$('#fixed_hdr2').fxdHdrCol({
        fixedCols: 0,
        width: "100%",
        height: 400,
        colModal: [
        { width: 50, align: 'center' },
        { width: 110, align: 'center' },
        { width: 170, align: 'left' },
        { width: 250, align: 'left' },
        { width: 100, align: 'left' },
        { width: 70, align: 'left' },
        { width: 100, align: 'left' },
        { width: 100, align: 'center' },
        { width: 90, align: 'left' },
        { width: 400, align: 'left' }
        ],
        sort: true
    });

And when I convert it into angular directives it will look like this:

myApp.directive('fixedTable', function () {
return {
    restrict: 'AE',
    link: function (scope, element, attrs) {
        element.fxdHdrCol({
            fixedCols: attrs.fixedCols,
            width: attrs.width,
            height: attrs.height,
            colModal: [
               { width: 80, align: 'left'},
               { width: 250, align: 'left'},
               { width: 100, align: 'left'},
               { width: 100, align: 'left'},
               { width: 130, align: 'left'},
               { width: 100, align: 'left'},
               { width: 150, align: 'left'},
               { width: 130, align: 'center'},
               { width: 100, align: 'left'},
               { width: 150, align: 'left'}
            ]
        });
    }
}; })

here's my error -> "TypeError: Cannot read property 'width' of undefined" I know I have mistake in converting but I don't know how to convert it correctly. Any help is very appreciated. Thanks

7
  • Sounds like something is trying to get width off of an object that is undefined. Is the error occurring inside the plugin? Commented Dec 7, 2014 at 16:05
  • yeah I already added it, <table fixed-table fixed-cols="3" height="300" width="100%"> I think my problem is in the colModal. I don't know how to convert this and call it in my element. Commented Dec 7, 2014 at 16:07
  • attr values will likely be string, test typeof to be sure. Also is jquery included before anugular library? Commented Dec 7, 2014 at 16:11
  • @charlietfl how? sorry but please give me example. Thanks Commented Dec 7, 2014 at 16:15
  • Did you try console.log(attrs)? what is inside attrs? Commented Dec 7, 2014 at 16:31

1 Answer 1

1

your html code?

Error:"TypeError: Cannot read property 'width' of undefined"

Possibility 1:width: attrs.width
Possibility 2:colModal and table's column are Inconsistent

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.