發表文章

目前顯示的是 10月, 2019的文章

[Angular] 回到最上面 goTop按鈕作法

使用 .scrollTo({options}) 的方式 可以調用JS的smooth方式,讓滾動畫面有動畫 直接使用 .scrollTo(位置) 會有種瞬移閃現到目的地的感覺 所以看使用情境選擇使用方式 HTML        < button   mat-raised-button   color = " primary "   (click) = " goTop() " >               填完了嗎?點我回到最上方              </ button > TS    goTop ()   {      //  window.scrollTo(0, 0); // 沒動畫      window . scrollTo ( {   left :   0 ,   top :   0 ,   behavior :   ' smooth '   } ) ;    } 參考: https://stackoverflow.com/questions/36092212/smooth-scroll-angular2

[Angular] 強制使FormGroup的表單驗證啟動方式

用法: this.Service.FormGroup.setErrors({invalid:true})   //  設定表單送出的那層formGroupd卡關        this . formDataService . serviceFormGroup          . get ( ' FundsList ' )          . setErrors ( {   invalid :   true   } ) ; stockoverflow上類似寫法 formData.form.controls['email'].setErrors({'incorrect': true}); 使用時機: 因為有時formgroup有階層 或是結構是formgroup包array 下面這範例就是FundsList和SecurtiesList都各自有包其他內容   createForm ()   {      this . serviceFormGroup   =   this . fb . group ( {              ApplicantDate :  [ '' ] ,             FundsList :   this . fb . array ([]) ,        SecuritiesList :   this . fb . array ([]) ,      ...