How to deal with losing deep imports in Angular 4

只愿长相守 提交于 2019-12-23 15:36:58

问题


I have just updated to Angular 4 and learned that it no longer supports deep imports.

So I was using VALID to help validate forms. But now that the I can't import it with the deep import

import { VALID } from '@angular/forms/src/model 

And since this does not work,

import { VALID } from '@angular/forms/'

What are we expected to do to access it? Or anything for that matter that was previously accessed with a deep import?


回答1:


Angular 4 no longer supports deep imports . In Angular 2 you could do this,

import { VALID } from '@angular/forms/src/model'  

but now in Angular 4 you can only go to the first level,

import { VALID } from '@angular/forms' 

So basically anything you were accessing by deep import is no longer useable if it is not exported, which would make it available so you can access it from that first level.

So in my case VALID was not reachable. So in order to validate I just validated it with the string response from checking the validation of the input field on blur instead of the bool.

formInputValidate(inputField: string, ErrorTitle: string, ErrorMessage: string) {
  if (this.profileForm.get(inputField).status === 'VALID') {
    this.toastSuccess(inputField, ' entered correctly');
  } else {
    this.toastWarning(ErrorTitle, ErrorMessage);
  }
}

Which raises a new question,

In my case this was an easy fix. But if the situation is more complicated and the deep import helper was critical, how do we get around this?

I asked the contributors of Angular on git here and they said,

So it appears that if there is someone we need we can request it and they will consider it!




回答2:


for ppl have the same problem, can refer to: https://github.com/angular/angular/issues/15542#issuecomment-289671010



来源:https://stackoverflow.com/questions/43060615/how-to-deal-with-losing-deep-imports-in-angular-4

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!