Buni qanday amalga oshirish kerak?

Menda bu funktsiya mavjud, lekin bu liniyani boshlanganda:        this.router.navigate (['/ home']); ishlaydi, lekin u mening kodimning qaerdaligini qaerda qo'ygan bo'lsa ishlamaydi. Har qanday taklif bormi?

 submitLogin(values){

     //Variable to hold a reference of addComment/updateComment
         let loginOperation:Observable;
         loginOperation = this.loginService.Login(values);
         loginOperation.subscribe(
            function(response) { console.log("Success Response" + response)},
            function(error) { console.log("Error happened" + error)},
            function(){
              this.router.navigate(['/home']);
               console.log("the subscription is completed");


             }
        );

   }
0

7 javoblar

Buni e'tiborsiz qoldiradigan yoki this misolini o'zgaruvchiga saqlash uchun ES6 sintaksisini foydalaning

submitLogin(values){
 var vm = this;
     //Variable to hold a reference of addComment/updateComment
         let loginOperation:Observable;
         loginOperation = this.loginService.Login(values);
         loginOperation.subscribe(
            function(response) { console.log("Success Response" + response)},
            function(error) { console.log("Error happened" + error)},
            function(){
              vm.router.navigate(['/home']);
               console.log("the subscription is completed");
             }
        );

   }

yoki buni ES6 bilan qilishingiz mumkin

submitLogin(values){
     //Variable to hold a reference of addComment/updateComment
         let loginOperation:Observable;
         loginOperation = this.loginService.Login(values);
         loginOperation.subscribe(
           (response) => { console.log("Success Response" + response)},
           (error) => { console.log("Error happened" + error)},
          () => {
              this.router.navigate(['/home']);
               console.log("the subscription is completed");
             }
        );

   }
2
qo'shib qo'ydi

Buni e'tiborsiz qoldiradigan yoki this misolini o'zgaruvchiga saqlash uchun ES6 sintaksisini foydalaning

submitLogin(values){
 var vm = this;
     //Variable to hold a reference of addComment/updateComment
         let loginOperation:Observable;
         loginOperation = this.loginService.Login(values);
         loginOperation.subscribe(
            function(response) { console.log("Success Response" + response)},
            function(error) { console.log("Error happened" + error)},
            function(){
              vm.router.navigate(['/home']);
               console.log("the subscription is completed");
             }
        );

   }

yoki buni ES6 bilan qilishingiz mumkin

submitLogin(values){
     //Variable to hold a reference of addComment/updateComment
         let loginOperation:Observable;
         loginOperation = this.loginService.Login(values);
         loginOperation.subscribe(
           (response) => { console.log("Success Response" + response)},
           (error) => { console.log("Error happened" + error)},
          () => {
              this.router.navigate(['/home']);
               console.log("the subscription is completed");
             }
        );

   }
2
qo'shib qo'ydi

this javascriptda tan olinmaganligi sababli joriy foydalanishingiz kerak.

submitLogin(values){
    var current = this;
    Variable to hold a reference of addComment/updateComment
    let loginOperation:Observable;
    loginOperation = this.loginService.Login(values);
    loginOperation.subscribe(
    function(response) { console.log("Success Response" + response)},
    function(error) { console.log("Error happened" + error)},
    function(){ current.router.navigate(['/home']);
                console.log("the subscription is completed"); });
}
1
qo'shib qo'ydi

When you are using angular 2 use ARROW FUNCTIONS() => {}

loginOperation.subscribe((response: any) => {
          console.log("Success Response" + response)
  }, (error: any) => {
          console.log("Error happened" + error)
  },() => {
          this.router.navigate(['/home']);
          console.log("the subscription is completed");
});
1
qo'shib qo'ydi

When you are using angular 2 use ARROW FUNCTIONS() => {}

loginOperation.subscribe((response: any) => {
          console.log("Success Response" + response)
  }, (error: any) => {
          console.log("Error happened" + error)
  },() => {
          this.router.navigate(['/home']);
          console.log("the subscription is completed");
});
1
qo'shib qo'ydi

Obuna ishlovchilaringizdagi funktsiya kalit so'zidan foydalanish yangi JavaScript-ni yaratishga sabab bo'ladi. Buning ma'nosi nimani anglatadiki, ushbu ishlovchilar ichida, bu kalit so'z sizning sinfingiz emas, balki boshqa narsaga ishora qiladi.

Ikkala tomon ham sizning komponentingizga a'zo obunachilaringizdan ma'lumot olishni va komponentingiz a'zolariga kirish yoki kerakli muammolarni butunlay chetlab o'tish zarur bo'lgan eskizdan foydalanishi yoki es2015 uslubidagi o'q funksiyasi deklaratsiyalaridan foydalanib, yangi doirasi va shuning uchun bu kalit so'z qiymatiga ta'sir qilmaydi

Boshqaruv 1:

onLogin() {
  let component = this;
   ...
  loginOperation.subscribe(
        function(response) { console.log("Success Response" + response)},
        function(error) { console.log("Error happened" + error)},
        function(){
          component.router.navigate(['/home']);
           console.log("the subscription is completed");


         }
    );


}

2-usul (afzal):

onLogin() {
     let loginOperation:Observable;
     loginOperation = this.loginService.Login(values);
     loginOperation.subscribe(
        (response) => { console.log("Success Response" + response)},
        (error) => { console.log("Error happened" + error)},
       () => {
          this.router.navigate(['/home']);
           console.log("the subscription is completed");

         }
    );
0
qo'shib qo'ydi

Obuna ishlovchilaringizdagi funktsiya kalit so'zidan foydalanish yangi JavaScript-ni yaratishga sabab bo'ladi. Buning ma'nosi nimani anglatadiki, ushbu ishlovchilar ichida, bu kalit so'z sizning sinfingiz emas, balki boshqa narsaga ishora qiladi.

Ikkala tomon ham sizning komponentingizga a'zo obunachilaringizdan ma'lumot olishni va komponentingiz a'zolariga kirish yoki kerakli muammolarni butunlay chetlab o'tish zarur bo'lgan eskizdan foydalanishi yoki es2015 uslubidagi o'q funksiyasi deklaratsiyalaridan foydalanib, yangi doirasi va shuning uchun bu kalit so'z qiymatiga ta'sir qilmaydi

Boshqaruv 1:

onLogin() {
  let component = this;
   ...
  loginOperation.subscribe(
        function(response) { console.log("Success Response" + response)},
        function(error) { console.log("Error happened" + error)},
        function(){
          component.router.navigate(['/home']);
           console.log("the subscription is completed");


         }
    );


}

2-usul (afzal):

onLogin() {
     let loginOperation:Observable;
     loginOperation = this.loginService.Login(values);
     loginOperation.subscribe(
        (response) => { console.log("Success Response" + response)},
        (error) => { console.log("Error happened" + error)},
       () => {
          this.router.navigate(['/home']);
           console.log("the subscription is completed");

         }
    );
0
qo'shib qo'ydi
Angular Uzbekistan
Angular Uzbekistan
107 ishtirokchilar

Guruh Angular bo'yicha muloqot qilish uchun ochilgan Sizni qiziqtirsa: @nodejs_uz @react_uz @angular_uz @yiiframework_uz @js_uzb @typescript_uzb @vuejs_uz @ngTashkent @laravel_uz @uzdevgroup Ish o'rinlari @UzDev_jobs

ngTashkent
ngTashkent
77 ishtirokchilar

Правила просты: 1. Не хамить 2. Не хейтить 3. Реакт не нужен Ссылки: https://t.me/angular_ru - старший брат https://t.me/angular_uz - ангулар на узбекском @js_uzb @vuejs_uz @react_uz @nodejs_uz @yiiframework_uz @uzdevgroup @UzDev_Jobs @tasdev_talks