0

I have a problem with using $ in constructor. ngOnInit() translate.instant etc. here is my code:

declare var $: any;
{
    var SelectedDevice = $("#select2-example-basic".val();
}

and here is what i got when I tried to run this code.

I do not know why I couldnt use $ in constructur ngOnInit Translate.instant etc. but it works in other functions , for instance: in

onClick(){
    var infoDataTable = $('#basic-table').DataTable().page.info();
}

.. there is no error or fail...

and here is my html cod:

    <div class="table-responsive">
        <table id="basic-table" class="data-table table table-striped nowrap table-hover" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>{{'Plate'|translate}}</th>
                    <th>{{'Driver Name'|translate}}</th>
                    <th>{{'Start Time'|translate}}</th>
                    <th>{{'Starting Address'|translate}}</th>
                    <th>{{'End Time'|translate}}</th>
                    <th>{{'Ending Address'|translate}}</th>
                    <th>{{'Work Duration'|translate}}</th>
                    <th>{{'Distance'|translate}}</th>
                </tr>
            </thead>
            <tbody>
                <tr *ngFor="let item of workDataReportList">
                    <td>{{item.Name}}</td>
                    <td>{{item.DriverName}}</td>
                    <td>{{item.StartTime | date:'dd.MM.yy hh:mm'}}</td>
                    <td>{{item.StartAddress}}</td>
                    <td>{{item.EndTime | date:'dd.MM.yy hh:mm'}}</td>
                    <td>{{item.EndAddress}}</td>
                    <td>{{item.RunningTime}}</td>
                    <td>{{item.Km | distance}}</td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

I was wondering if it would be possible to help me about how can ı Use $ for this issues? thanks in advance...

for doing npm install @types/jquery I got this error:error is here

Derya Acar
  • 11
  • 1
  • FWIW, ^ that post was found by simply googling 'angular2 and jquery'. It's the first result. Please do a bit more research next time. – Rob Mar 17 '17 at 08:17
  • it does not mean it is the same thing and working that you found by simply googling. thats why I wrote here to solve this problem. – Derya Acar Mar 17 '17 at 11:58

2 Answers2

1

instead of declare var $: any;

Try installing the type definitions for jQuery:

npm install @types/jquery
Michael Kang
  • 52,003
  • 16
  • 103
  • 135
  • I've already tried to do this. but it doesn't work. here is what I got : "Module build failed: Error:....: Modue '"jqueryt"' has no default export.)" I also wrote ` import $ from "jquery" ` to solve this error. and it didnt work too. – Derya Acar Mar 17 '17 at 08:05
  • @DeryaAcar Please paste the exact error you receive. Don't simply type it, as you'll end up with incorrect solutions (for example you misspelled jqueryt, we can't tell if the error is because you misspelled it in your code, or misspelled it while writing the error message). – Rob Mar 17 '17 at 08:11
0

you can install jquery libary : npm install --save @types/jquery
you should use jQuery instead $ example:

jQuery("#select2-example-basic".val();
love prince
  • 149
  • 1
  • 7