0
  • I am new to typescript and angular 2.
  • I am trying to include my my tabs code in typescript method and run it but its not running.
  • i am trying to put in a method so that I can write a test case by callling that method.
  • i used angular 2 click (click)="myFunc()" but its not working
  • can you guys tell me how to fix it.
  • providing my code and error below

https://jsfiddle.net/z4vo5u5d/409/

error: 

VM212:11 Uncaught ReferenceError: require is not defined
    at eval (eval at exec (VM85 typescript.js:41), <anonymous>:11:14)
    at exec (VM85 typescript.js:41)
    at HTMLDocument.runScripts (VM85 typescript.js:41)

code: 

        <li (click)="myFunc()" class="tab-link current" data-tab="tab-1">Tab One</li>
   var tab_id = $(this).attr('data-tab');

                $('ul.tabs li').removeClass('current');
                $('.tab-content').removeClass('current');

                $(this).addClass('current');
                $("#"+tab_id).addClass('current');
  }
  • @KobyDouek thanks for your reply...hey I looked at your link but not able to find out how to implement solution...can you update in my fiddle...so confusing :( –  Aug 27 '17 at 12:24
  • Learn Angular from a something a little more up to date: https://angular.io/tutorial. What you are looking at is from v 2 beta 7. The current version is 4.3.6. – R. Richards Aug 27 '17 at 12:34
  • @R.Richards hey, I am using angular 2 that's the reason I am trying to implement in angular 2...can you update in my fiddle it's so confusing. I went through the tutorials but not able to figure it out :( –  Aug 27 '17 at 12:40

2 Answers2

0

Have you declared require in import section?

declare var require: any;
Raja Mohamed
  • 1,026
  • 9
  • 22
  • I update your code in the fiddle but still its not working https://jsfiddle.net/z4vo5u5d/411/ –  Aug 27 '17 at 12:32
0

It's TSD issue create local project and ,update tsd

npm install -g tsd@latest
Raja Mohamed
  • 1,026
  • 9
  • 22
  • hey it's in fiddle I won't be able to do npm in fiddle...any other solution why myFunc is not getting called :( –  Aug 27 '17 at 12:44
  • I aware , create and update tsd in ur own machine. I have declared and used require many times. This is not code issue it's environment issue. You can't change environment in jsfiddle – Raja Mohamed Aug 27 '17 at 12:48
  • without that can't I make it work in my fiddle...since I am trying to call this method myFunc –  Aug 27 '17 at 12:59
  • I Appreciate, keep trying – Raja Mohamed Aug 27 '17 at 13:04
  • can you tell me why I am not able to call the myFunc method –  Aug 27 '17 at 13:14
  • I hope You dont have control over other components so only you are not able to access a method which is available in other component. You should bring the code into main component's template. Currently you have written the tabs HTML code in index.html I hope. From there you don't have access to any of components. It will just print the content what you have written there – Raja Mohamed Aug 27 '17 at 13:55
  • To verify this just create a this variable in components and print near the tabs , you won't see the string of the variable – Raja Mohamed Aug 27 '17 at 13:57