错误:[$ injector:nomod]模块'app'不可用

时间:2017-06-04 20:55:43

标签: angular angular-ui-router angular2-routing

请有人帮忙吗。我没有任何Angular 1到2迁移的经验。 我有这个代码

   import * as angular from 'angular';
   import 'angular-resource';
   import '@uirouter/angularjs';

export const app = angular.module('app', ['ui.router', 'ngResource'])
  .config(($stateProvider) => {
      $stateProvider
          .state('app1', {
              url: '/app1',
              component: 'app1'
          })
          .state('app2', {
              url: '/app2/:id',
              component: 'app2'
          })
          .state('app3', {
              url: '/app3',
              component: 'app3'
          })
          .state('app4', {
              url: '/app4',
              component: 'app4'
          })
    });

 import 'angular'
 import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
 import { UpgradeModule } from '@angular/upgrade/static'
 import {AppModule} from './app.module';
 import {app} from "./app";

 //I try to use first variant
 
 platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
    const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
    upgrade.bootstrap(document.body, ['app'], {strictDi: true});
});

    //and second 

platformBrowserDynamic().bootstrapModule(AppModule).then(ref => {
    const upgrade = (<any>ref.instance).upgrade;
    upgrade.bootstrap(document.body, [app.name]);
});

并在第一次出现此错误后:

错误:[$ injector:nomod]模块'app'不可用!您要么错误拼写了模块名称,要么忘记加载它。如果注册模块,请确保将依赖项指定为第二个参数。

第二次改变之后:

错误:TypeError:angular.module不是函数

app.module.ts

import {NgModule} from '@angular/core';
import {BrowserModule} from "@angular/platform-browser";
import {UpgradeModule} from "@angular/upgrade/static";

import {AppComponent} from "./app.component"

@NgModule({
    imports: [BrowserModule, UpgradeModule],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule {
    constructor(public upgrade: UpgradeModule){}
}

的package.json

{
  "name": "app",
  "version": "0.0.1",
  "description": "app to migrate",
  "keywords": [],
  "homepage": "http://angularjs.org/",
  "main": "scripts/server.js",
  "scripts": {
    "build": "webpack",
    "build:watch": "tsc -p  -w",
    "build:e2e": "tsc -p e2e/",
    "serve": "lite-server -c=bs-config.json",
    "serve:e2e": "lite-server -c=bs-config.e2e.json",
    "prestart": "npm run build",
    "start": "concurrently \"npm run build:watch\" \"npm run serve\"",
    "pree2e": "npm run build:e2e",
    "e2e": "concurrently \"npm run serve:e2e\" \"npm run protractor\" --kill-others --success first",
    "preprotractor": "webdriver-manager update",
    "protractor": "protractor protractor.config.js",
    "pretest": "npm run build",
    "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
    "pretest:once": "npm run build",
    "test:once": "karma start karma.conf.js --single-run",
    "lint": "tslint ./**/*.ts -t verbose"
  },
  "dependencies": {
    "@angular/common": "~4.0.0",
    "@angular/compiler": "~4.0.0",
    "@angular/compiler-cli": "^4.1.3",
    "@angular/core": "~4.0.0",
    "@angular/forms": "~4.0.0",
    "@angular/http": "~4.0.0",
    "@angular/platform-browser": "~4.0.0",
    "@angular/platform-browser-dynamic": "~4.0.0",
    "@angular/router": "~4.0.0",
    "@angular/upgrade": "^4.1.3",
    "@uirouter/angularjs": "^1.0.3",
    "angular": "^1.6.1",
    "angular-in-memory-web-api": "~0.3.0",
    "angular-resource": "^1.6.1",
    "body-parser": "^1.17.2",
    "core-js": "^2.4.1",
    "csv": ">= 0.2.1",
    "express": ">= 3.0.0",
    "morgan": "^1.8.2",
    "open": ">= 0.0.2",
    "reflect-metadata": "^0.1.10",
    "rxjs": "5.0.1",
    "systemjs": "0.19.40",
    "testacular": "canary",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^4.0.0",
    "@ngtools/webpack": "1.2.4",
    "@types/jasmine": "2.5.36",
    "@types/node": "^6.0.46",
    "canonical-path": "0.0.2",
    "concurrently": "^3.2.0",
    "jasmine-core": "~2.4.1",
    "karma": "^1.3.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "lite-server": "^2.2.2",
    "lodash": "^4.16.4",
    "protractor": "~4.0.14",
    "rimraf": "^2.5.4",
    "tslint": "^3.15.1",
    "typescript": "~2.1.0",
    "webpack": "^2.6.1"
  },
  "engines": {
    "node": ">= 0.8.4"
  },
  "license": "MIT"
}

0 个答案:

没有答案