如何应对Angular 4中丢失的深进口商品 [英] How to deal with losing deep imports in Angular 4

查看:83
本文介绍了如何应对Angular 4中丢失的深进口商品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚更新到Angular 4,并了解到它不再支持deep imports.

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

因此,我使用VALID来帮助验证表单.但现在我无法使用deep import

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 

由于这行不通,

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

我们应该怎么做才能访问它?还是以前使用deep import访问过的任何内容?

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

推荐答案

Angular 4不再支持深度导入.在Angular 2中,您可以这样做

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

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

但是现在在Angular 4中,您只能进入第一级,

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.

因此,在我的情况下,VALID无法访问.因此,为了进行验证,我只是通过检查模糊而不是布尔值的输入字段的有效性来使用字符串响应来对其进行验证.

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?

我在git上向Angular的贡献者问了,他们说,

因此,似乎如果有人需要我们,我们可以提出要求,他们会考虑的!

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

这篇关于如何应对Angular 4中丢失的深进口商品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆