0

I am new to Angular 2.

I am working on tour of heroes app from Angular.io. I am modifying it to have my hands on with Angular 2.

I have made a button which when clicked gives me popup. Right now I am implementing the pop up and then I came across this dependencies" --ng2-opd-popup."

I was adding it into the project so that I can use pop ups, but here the things got bad.

I did the following steps to add the dependency:

  1. made an entry in package.json "ng2-opd-popup": "^1.1.21",
  2. ran command - npm install ng2-opd-popup --save .
  3. Imported it in app.module.ts .import { PopupModule } from 'ng2-opd-popup';
  4. ran the server:

but it gave error:

enter image description here

My package JSON

{
  "name": "angular-io-example",
  "version": "1.0.0",
  "private": true,
  "description": "Example project from an angular.io guide.",
  "scripts": {
    "test:once": "karma start karma.conf.js --single-run",
    "build": "tsc -p src/",
    "serve": "lite-server -c=bs-config.json",
    "prestart": "npm run build",
    "start": "concurrently \"npm run build:watch\" \"npm run serve\"",
    "pretest": "npm run build",
    "test": "concurrently \"npm run build:watch\" \"karma start karma.conf.js\"",
    "pretest:once": "npm run build",
    "build:watch": "tsc -p src/ -w",
    "build:upgrade": "tsc",
    "serve:upgrade": "http-server",
    "build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup-config.js",
    "serve:aot": "lite-server -c bs-config.aot.json",
    "build:babel": "babel src -d src --extensions \".es6\" --source-maps",
    "copy-dist-files": "node ./copy-dist-files.js",
    "i18n": "ng-xi18n",
    "lint": "tslint ./src/**/*.ts -t verbose"
  },
  "keywords": [],
  "author": "",
  "license": "MIT",
  "dependencies": {
    "@angular/animations": "~4.3.1",
    "@angular/common": "~4.3.1",
    "@angular/compiler": "~4.3.1",
    "@angular/compiler-cli": "~4.3.1",
    "@angular/core": "~4.3.1",
    "@angular/forms": "~4.3.1",
    "@angular/http": "~4.3.1",
    "@angular/platform-browser": "~4.3.1",
    "@angular/platform-browser-dynamic": "~4.3.1",
    "@angular/platform-server": "~4.3.1",
    "@angular/router": "~4.3.1",
    "@angular/tsc-wrapped": "~4.3.1",
    "@angular/upgrade": "~4.3.1",
    "angular-in-memory-web-api": "~0.3.2",
    "core-js": "^2.4.1",
    "ng2-opd-popup": "^1.1.21",
    "rxjs": "^5.1.0",
    "systemjs": "0.19.39",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@types/angular": "^1.5.16",
    "@types/angular-animate": "^1.5.5",
    "@types/angular-cookies": "^1.4.2",
    "@types/angular-mocks": "^1.5.5",
    "@types/angular-resource": "^1.5.6",
    "@types/angular-route": "^1.3.2",
    "@types/angular-sanitize": "^1.3.3",
    "@types/jasmine": "2.5.36",
    "@types/node": "^6.0.45",
    "babel-cli": "^6.16.0",
    "babel-preset-angular2": "^0.0.2",
    "babel-preset-es2015": "^6.16.0",
    "canonical-path": "0.0.2",
    "concurrently": "^3.0.0",
    "http-server": "^0.9.0",
    "jasmine": "~2.4.1",
    "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",
    "karma-phantomjs-launcher": "^1.0.2",
    "lite-server": "^2.2.2",
    "lodash": "^4.16.2",
    "phantomjs-prebuilt": "^2.1.7",
    "protractor": "~5.1.0",
    "rollup": "^0.41.6",
    "rollup-plugin-commonjs": "^8.0.2",
    "rollup-plugin-node-resolve": "2.0.0",
    "rollup-plugin-uglify": "^1.0.1",
    "source-map-explorer": "^1.3.2",
    "tslint": "^3.15.1",
    "typescript": "~2.3.2"
  },
  "repository": {}
}

BELOW IS MY app.module.ts :-

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule }   from '@angular/forms';
import { HttpModule }    from '@angular/http';

import { AppRoutingModule } from './app-routing.module';

// Imports for loading & configuring the in-memory web api
import { InMemoryWebApiModule } from 'angular-in-memory-web-api';
import { InMemoryDataService }  from './in-memory-data.service';

import { AppComponent }         from './app.component';
import { DashboardComponent }   from './dashboard.component';
import { HeroesComponent }      from './heroes.component';
import { HeroDetailComponent }  from './hero-detail.component';
import { HeroService }          from './hero.service';
import { ProfileService }       from './profile.service';
import { HeroSearchComponent }  from './hero-search.component';
import { PopupModule }          from 'ng2-opd-popup';


@NgModule({
  imports: [
    BrowserModule,
    FormsModule,
    PopupModule.forRoot(),
    HttpModule,
    //InMemoryWebApiModule.forRoot(InMemoryDataService),
    AppRoutingModule
  ],
  declarations: [
    AppComponent,
    DashboardComponent,
    HeroDetailComponent,
    HeroesComponent,
    HeroSearchComponent
  ],
  providers: [ HeroService ,ProfileService],
  bootstrap: [ AppComponent ]
})
export class AppModule { }

my system.config.js

/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      'app': 'app',

      // angular bundles
      '@angular/animations': 'npm:@angular/animations/bundles/animations.umd.js',
      '@angular/animations/browser': 'npm:@angular/animations/bundles/animations-browser.umd.js',
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser/animations': 'npm:@angular/platform-browser/bundles/platform-browser-animations.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/router/upgrade': 'npm:@angular/router/bundles/router-upgrade.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
      '@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
      '@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js',

      // other libraries
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
      'ng2-opd-popup' : 'npm:ng2-opd-popup'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.js',
        defaultExtension: 'js',
        meta: {
          './*.js': {
            loader: 'systemjs-angular-loader.js'
          }
        }
      },
      rxjs: {
        defaultExtension: 'js'
      }
    }
  });
})(this);

how can I add the dependency ng2-opd-popup so that the app can use it in the project? I have spent hours googling and I cant figure out any way now.

output for npm install ng2-opd-popup

H:\Heros>npm install ng2-opd-popup --save
angular-io-example@1.0.0 H:\Heros
`-- ng2-opd-popup@1.1.21
  +-- UNMET PEER DEPENDENCY @angular/common@2.3.0
  +-- UNMET PEER DEPENDENCY @angular/compiler@2.2.4
  +-- @angular/compiler-cli@2.3.0
  | `-- @angular/tsc-wrapped@0.4.2
  |   `-- tsickle@0.2.6
  +-- UNMET PEER DEPENDENCY @angular/core@2.3.0
  +-- @angular/forms@2.3.0
  +-- @angular/http@2.3.0
  +-- UNMET PEER DEPENDENCY @angular/platform-browser@2.3.0
  +-- @angular/platform-browser-dynamic@2.3.0
  +-- @angular/router@3.2.4
  +-- UNMET PEER DEPENDENCY rxjs@5.0.0-rc.4
  `-- zone.js@0.7.8

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","ar
ch":"x64"})
npm WARN enoent ENOENT: no such file or directory, open 'H:\Heros\node_modules\angular2-modal\package.json'
npm WARN @angular/platform-browser-dynamic@2.3.0 requires a peer of @angular/compiler@2.3.0 but none was installed.
npm WARN @angular/compiler-cli@2.3.0 requires a peer of @angular/compiler@2.3.0 but none was installed.
npm WARN @angular/router@3.2.4 requires a peer of @angular/core@2.2.4 but none was installed.
npm WARN @angular/router@3.2.4 requires a peer of @angular/common@2.2.4 but none was installed.
npm WARN @angular/router@3.2.4 requires a peer of @angular/platform-browser@2.2.4 but none was installed.
npm WARN @angular/router@3.2.4 requires a peer of rxjs@5.0.0-beta.12 but none was installed.
npm WARN @angular/compiler@2.2.4 requires a peer of @angular/core@2.2.4 but none was installed.
user3668556
  • 55
  • 3
  • 12
  • Just a note -- using `npm install _____ --save` will add that line to the package.json file for you. – Reticulated Spline Aug 07 '17 at 15:47
  • Ohh okay , thanks for the info .Any help with the problem ??? I am really struggling – user3668556 Aug 07 '17 at 15:50
  • Looks like it can't find the package in `node_modules`. What is the output of `npm install ng2-opd-popup --save`? – Reticulated Spline Aug 07 '17 at 15:55
  • @ReticulatedSpline I have included the output please see . – user3668556 Aug 07 '17 at 16:00
  • Error seems to be in system.config.js. check 'ng2-opd-popup' : 'npm:ng2-opd-popup' – mehta-rohan Aug 07 '17 at 16:06
  • I would also consider trying an `npm update` or deleting `node_modules` and then rebuilding them with `npm install`. It seems a lot of packages are missing dependencies. There's a good discussion on that topic [here.](https://stackoverflow.com/questions/12866494/how-do-you-reinstall-an-apps-dependencies-using-npm) – Reticulated Spline Aug 07 '17 at 16:09
  • be sure about the path you are specified for ng2-opd-popup. As I can observe it must be placed in the same directory as of rxjs. – mehta-rohan Aug 07 '17 at 16:09
  • @mehta-rohan ,what do you mean by specifying th path ?? I have never specified any path , I just did npm install ng2-opd-popup and it came automatically inside mode_modules and finally I used it into the component with import statement ..Is there some place where path needs to be placed , if yes then where ?please specify? – user3668556 Aug 08 '17 at 07:52
  • you can separately install it and do 'ng2-opd-pop' : '/path/ng2-opd-pop' – mehta-rohan Aug 08 '17 at 08:48
  • @mehta-rohan ok so you mean that like my ng2-opd-popup is at path 'H:\Heros\node_modules\ng2-opd-popup' so inside systemconfig .js I can write 'ng2-opd-pop' : 'H:\Heros\node_modules\ng2-opd-popup' Am I correct to say this ? – user3668556 Aug 08 '17 at 09:14
  • @mehta-rohan if you mean what I have written in comment , then I want to tell that I have just now tried it and still get not able to proceed ,. – user3668556 Aug 08 '17 at 09:35

0 Answers0