Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 无法解析DOM组件SharedStylesHost_Angular - Fatal编程技术网

Angular 无法解析DOM组件SharedStylesHost

Angular 无法解析DOM组件SharedStylesHost,angular,Angular,我将我的应用程序从2.4更新到4.0.3。还有一个错误我自己无法修复 ./src/app/app.component.ts Module not found: Error: Can't resolve '@angular/platform-browser/src/dom/shared_styles_host' in 'C:\solutions\projectx\src\app' TypeScript编译器在终端中告诉您: [at-loader] ./src/app/app.component.

我将我的应用程序从2.4更新到4.0.3。还有一个错误我自己无法修复

./src/app/app.component.ts
Module not found: Error: Can't resolve '@angular/platform-browser/src/dom/shared_styles_host' in 'C:\solutions\projectx\src\app'
TypeScript编译器在终端中告诉您:

[at-loader] ./src/app/app.component.ts:47:44
TS2304: Cannot find name 'SharedStylesHost'.
我做错了什么?同样在angular.io上,我没有发现任何提示

编辑:添加了app.component.ts

import {
    Component, ElementRef, NgZone, OnInit, Renderer2, ViewChild, 
    ViewEncapsulation
} from '@angular/core';
import { AppState } from './app.service';
import {
    Event as RouterEvent,
    NavigationCancel,
    NavigationEnd,
    NavigationError,
    NavigationStart,
    Router
} from '@angular/router';
import { DeviceDetectionService } from 'shared-signup';
import { ElementQueriesService } from 'shared-angular';
import { ELEMENT_QUERIES } from './shared-models/element-queries.const';
import { SharedStylesHost } from '@angular/platform-browser/src/dom/shared_styles_host';

const EQ: any = require('css-element-queries/src/ElementQueries');

@Component({
    selector: 'app',
    encapsulation: ViewEncapsulation.None,
    styleUrls: [
        './app.styles.scss'
    ],
    templateUrl: './app.template.html',
    providers: [
        ElementQueriesService
    ]
})
export class AppComponent implements OnInit {

@ViewChild('loadingElement')
    public loadingElement: ElementRef;

    public ELEMENT_QUERIES: ({ name: string, 'max-width': string } | { name: string, 'min-width': string })[];

    constructor(public appState: AppState,
            private _sharedStylesHost: SharedStylesHost,
            private _router: Router,
            private _ngZone: NgZone,
            private _renderer: Renderer2,
            private _elementQueriesService: ElementQueriesService) {

    this.ELEMENT_QUERIES = ELEMENT_QUERIES;

    _router.events.subscribe((event: RouterEvent) => {
        this._navigationInterceptor(event);
    });

    DeviceDetectionService.customMobileDetection = function () {
        return _elementQueriesService.hasSize(['small']);
    };

    /*
     ugly workaround to avoid initial layout problems with slow connections

     If the connection is slow and the files are not cached, the document.styleSheets.length property is smaller then 5, even if the onStylesAdded method is call (whyever).
     To avoid the problem, check the style length until it is bigger then five, then init the ElementQueries plugin.
     ToDo: find a better place to init ElementQueries, or build a simple service for it
     */
    const oldOnStylesAdded = (<any>_sharedStylesHost).onStylesAdded;
    let checkStyleLength = function () {
        (document.styleSheets.length < 5)
            ? setTimeout(checkStyleLength, 300)
            : EQ.init(true);
    };

    checkStyleLength();

    (<any>_sharedStylesHost).onStylesAdded = (additions: string[]) => {
        oldOnStylesAdded.apply(this._sharedStylesHost, [additions]);
        EQ.init(true);
    };

  }
}
导入{
组件、ElementRef、NgZone、OnInit、渲染器2、ViewChild、,
视图封装
}从“@angular/core”开始;
从“/app.service”导入{AppState};
进口{
事件作为RouterEvent,
导航取消,
导航终端,
导航错误,
导航开始,
路由器
}来自“@angular/router”;
从“共享注册”导入{DeviceDetectionService};
从“共享”导入{ElementQueriesService};
从“./shared models/ELEMENT querys.const”导入{ELEMENT_querys};
从“@angular/platform browser/src/dom/shared_styles_host”导入{SharedStylesHost}”;
const EQ:any=require('css-element-querys/src/elementquerys');
@组成部分({
选择器:“应用程序”,
封装:视图封装。无,
样式URL:[
“./app.styles.scss”
],
templateUrl:'./app.template.html',
供应商:[
元素查询服务
]
})
导出类AppComponent实现OnInit{
@ViewChild('loadingElement')
公共加载元素:ElementRef;
公共元素_查询:({name:string,'max-width':string}{name:string,'min-width':string})[];
构造函数(公共appState:appState,
private _sharedStylesHost:sharedStylesHost,
专用路由器:路由器,
私人(ngZone):ngZone,,
私有渲染器:渲染器2,
private _elementQueriesService:elementQueriesService){
this.ELEMENT\u querys=ELEMENT\u querys;
_router.events.subscribe((事件:RouterEvent)=>{
本导航接收器(事件);
});
DeviceDetectionService.customMobileDetection=函数(){
return _elementQueriesService.hasSize(['small']);
};
/*
丑陋的解决方法,以避免连接缓慢时出现初始布局问题
如果连接速度慢且文件未缓存,则document.styleSheets.length属性小于5,即使onStylesAdded方法是call(whyever)。
为了避免这个问题,请检查样式长度,直到它大于5,然后初始化ElementQueries插件。
ToDo:找一个更好的地方初始化ElementQueries,或者为它构建一个简单的服务
*/
const-oldOnStylesAdded=(_-sharedStylesHost).onStylesAdded;
让checkStyleLength=函数(){
(document.styleSheets.length<5)
?设置超时(checkStyleLength,300)
:EQ.init(真);
};
checkStyleLength();
(_sharedStylesHost).onStylesAded=(添加:string[])=>{
OldonStylesAded.apply(此._sharedStylesHost,[添加]);
等式init(真);
};
}
}

app.component.ts你能给我们看一下吗code?你不能再使用私有API了
import{SharedStylesHost}从“@angular/platform browser/src/dom/shared_styles_host”导入{SharedStylesHost}您可以尝试从“@angular/platform browser”导入{ɵSharedStylesHost}”相反,这起作用了!现在我有一个follow错误,但这很容易修复。谢谢!很高兴听到!咬@yurzui你应该回答你的评论。这对我很有效,你能给我们看一下
app.component.ts
code吗?你不能再使用私有API了
import{SharedStylesHost}从'@angular/platform browser/src/dom/shared_styles_host'中您可以尝试从“@angular/platform browser”导入{ɵSharedStylesHost}”相反,这起作用了!现在我有一个follow错误,但这很容易修复。谢谢!很高兴听到!咬@yurzui你应该回答你的评论。这对我也有用