0

I am trying to use the Jquery Bracket library on my ionic 2 typescript app. However, the library does not has type definitions. So, I tried to use it traditionally. I placed js and CSS file of the library into my src/assets folder and I added necessary tags into my src/index.html file. Lastly, I declare a variable on my typescript file and tried to use it like it's suggested on the examples on the library site.

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import * as $ from 'jquery'

declare var Options: any;

    @Component({
      selector: 'page-tournament-schedule',
      templateUrl: 'tournament-schedule.html'
    })
    export class TournamentSchedulePage {

      constructor(public navCtrl: NavController) {
      }

      ionViewDidLoad() {
        console.log('Hello TournamentSchedule Page');
        this.getBrackets();
      }

      getBrackets() {
        var singleElimination = {
          "teams": [              // Matchups
            ["Team 1", "Team 2"], // First match
            ["Team 3", "Team 4"]  // Second match
          ],
          "results": [            // List of brackets (single elimination, so only one bracket)
            [                     // List of rounds in bracket
              [                   // First round in this bracket
                [1, 2],           // Team 1 vs Team 2
                [3, 4]            // Team 3 vs Team 4
              ],
              [                   // Second (final) round in single elimination bracket
                [5, 6],           // Match for first place
                [7, 8]            // Match for 3rd place
              ]
            ]
          ]
        }
        $('.demo').Options.bracket({
          init: singleElimination
        });
      }
    }

But, it's giving me the following error

Cannot read property 'bracket' of undefined

4
  • Where from you get Options ? I can't find it in docs, I think your issue isn't connected with type definitions, just your $('.demo').Options is undefined., btw, if you want you can add custom typings for that lib to your project. Commented Jul 14, 2017 at 12:03
  • I tried it like just bracket it's also not working @AlexanderTuniev Commented Jul 14, 2017 at 12:04
  • with same error ? Commented Jul 14, 2017 at 12:04
  • @AlexanderTuniev it's saying bracket is not defined Commented Jul 14, 2017 at 12:06

1 Answer 1

0

Try the following. Create a ts file, name it customTyping.d.ts or something similar, add folowing content,

    interface JQuery {
      brackets?: any;
    }

Then include that file in tsconfig.json

"include": [
    "...",
    "...",
    "pathto/customTypings.d.ts"
  ]

This way you will have type definition for brackets in JQuery. Let me know if this helps.

Sign up to request clarification or add additional context in comments.

5 Comments

after doing this, do I need to declare a variable again or can I use it like in the documentation?
I used it like in the documentation and it is saying bracket is not a function
how do you included that library in your project ?, maybe it is not available?
I installed it via npm then I placed js and css files into src/assets folder then I included the tags to my src/index.html file
check this out, netbasal.com/…

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.