首页 > 解决方案 > Nativescript Angular 错误 NG8001:“StackLayout”不是已知元素:

问题描述

src/app/components/dashboard/dashboard.component.html:1:1 中的错误 - 错误 NG8001:'StackLayout' 不是已知元素:

  1. 如果“StackLayout”是一个 Angular 组件,则验证它是否是该模块的一部分。
  2. 要允许任何元素,请将“NO_ERRORS_SCHEMA”添加到该组件的“@NgModule.schemas”中。

1

仪表板.component.tns.html

<StackLayout>
  <Label text="dashboard works" textWrap="true"></Label>
  <Label text="This is a migrated component" textWrap="true"></Label>
  <Label text="Update it to provide the UI elements required in your mobile app" textWrap="true"></Label>
</StackLayout>

包.json

{
  "name": "angular-google-identity",
  "version": "0.0.0",
  "scripts": {
    "android": "ns run android --no-hmr",
    "ios": "ns run ios --no-hmr",
    "mobile": "ns run",
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "eslint": "eslint 'src/**/*.ts'",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^10.1.5",
    "@angular/common": "~10.0.9",
    "@angular/compiler": "~10.0.9",
    "@angular/core": "~10.0.9",
    "@angular/forms": "~10.0.9",
    "@angular/localize": "~10.0.9",
    "@angular/platform-browser": "~10.0.9",
    "@angular/platform-browser-dynamic": "~10.0.9",
    "@angular/router": "~10.0.9",
    "@angular/service-worker": "~10.0.9",
    "@nativescript/angular": "~10.1.0",
    "@nativescript/core": "~7.0.0",
    "@nativescript/theme": "~2.5.0",
    "@ng-bootstrap/ng-bootstrap": "^7.0.0",
    "@stomp/ng2-stompjs": "^7.2.0",
    "@types/node-rsa": "^1.0.0",
    "@types/socket.io-client": "^1.4.33",
    "aes-js": "^3.1.2",
    "angularx-social-login": "^3.2.1",
    "bootstrap": "^4.5.0",
    "constants": "0.0.2",
    "core-js": "^3.6.5",
    "crypto": "^1.0.1",
    "event-source-polyfill": "^1.0.16",
    "idb": "^5.0.4",
    "mediasoup-client": "^3.6.12",
    "moment": "^2.27.0",
    "nativescript-secure-storage": "^2.6.2",
    "ng-gapi": "0.0.93",
    "ngx-avatar": "^4.0.0",
    "ngx-contextmenu": "^5.4.0",
    "ngx-infinite-scroll": "^9.0.0",
    "ngx-link-preview": "^1.1.6",
    "ngx-logger": "^4.1.9",
    "ngx-webcam": "^0.3.0",
    "node-rsa": "^1.1.1",
    "primeng": "^10.0.0-rc.3",
    "recordrtc": "^5.6.1",
    "reflect-metadata": "~0.1.12",
    "rxjs": "~6.6.2",
    "rxjs-compat": "^6.6.3",
    "secure-ls": "^1.2.6",
    "socket.io": "^2.3.0",
    "socket.io-client": "^2.3.0",
    "stompjs": "^2.3.3",
    "tslib": "^2.0.1",
    "webrtc-adapter": "^7.7.0",
    "zone.js": "~0.10.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1000.6",
    "@angular/cli": "~10.0.6",
    "@angular/compiler-cli": "~10.0.9",
    "@angular/language-service": "~10.0.9",
    "@nativescript/android": "7.0.0",
    "@nativescript/schematics": "^10.1.0",
    "@nativescript/tslint-rules": "~0.0.5",
    "@nativescript/webpack": "~3.0.0",
    "@types/jasmine": "~3.5.12",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^14.6.0",
    "@typescript-eslint/eslint-plugin": "^4.1.0",
    "@typescript-eslint/eslint-plugin-tslint": "^3.9.1",
    "@typescript-eslint/parser": "^4.1.0",
    "codelyzer": "~6.0.0",
    "eslint": "^7.8.1",
    "eslint-config-google": "^0.14.0",
    "jasmine-core": "~3.6.0",
    "jasmine-spec-reporter": "~5.0.2",
    "karma": "~5.1.1",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~3.0.3",
    "karma-jasmine": "~4.0.1",
    "karma-jasmine-html-reporter": "^1.5.4",
    "protractor": "^7.0.0",
    "ts-node": "~8.10.2",
    "tslint": "~6.1.3",
    "typescript": "~3.9.7"
  },
  "main": "main.tns.js"
}

app.module.tns.ts 也有模式:[NO_ERRORS_SCHEMA]

运行tns build android --bundle时遇到错误

标签: angularnativescript

解决方案


刚刚意识到 app.module.tns.ts 没有声明可以解决问题的 Dashboard 组件。

@NgModule({
  declarations: [
    AppComponent,
    AutoGeneratedComponent,
    DashboardComponent
  ],

推荐阅读