全局Angular CLI版本(7.2.2)大于本地版本

时间:2019-01-23 15:27:50

标签: angular6

我正在使用Angular 2应用程序,尝试使用CLI创建组件时出现错误。

命令

ng g c mycomponent

我已经尝试通过执行以下操作来重新安装cli,但似乎没有用

ng new my-project
cd my-project
ng g c my-component --m app

错误

Your global Angular CLI version (7.2.2) is greater than your local
version (6.0.8). The local Angular CLI version is used.

To disable this warning use "ng config -g cli.warnings.versionMismatch false".
Could not find an NgModule. Use the skip-import option to skip importing in NgModule.

ng版本检查Visual Studio代码

enter image description here

在cmd上进行ng版本检查

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试删除整个项目,然后在将组件cd创建到应用文件夹中时,键入以下内容。

checkIfDataAvailable(movies) {
        if(movies.length) {
            return (
                    <Row>
                        {movies.map(movie =>
                            <Col sm="3">
                                <Movie 
                                    key={movie.id}
                                    title={movie.title}
                                    src={`${baseImgUrl}/${movie.poster_path}`}
                                />
                            </Col>    
                        )}
                    </Row>        
            )
        } else {
            console.log('Is Loading....')
        }
    }

render() {
        return (
            <div className="Home">
                <div className="Home-header">
                    <div className="Home-headline">
                        <Container fluid>
                            <h1 className="Home-headline__primary">Welcome To Movie Hunter Website</h1>
                            <p className="Home-headline__secondary">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut suscipit condimentum ligula, et ultricies lectus ligula, et ultricies lectus ligula, et ultricies lectus.</p>
                            <Button className="Home-headline-button">Into the Site</Button>
                        </Container>
                    </div>
                </div>

                <div className="Home-main">
                    <Container>
                        <h2 className="Home-main-primary">Popular Movies</h2>
                            {this.checkIfDataAvailable(this.state.popularMovies)} 
                    </Container>

                    <Container>
                        <h2 className="Home-main-primary">Top Rated Movies</h2>
                         {this.checkIfDataAvailable(this.state.topRatedMovies)}
                    </Container>
                </div>                
            </div>
        )
    }

肯定会创建一个组件。