dougludlow / ng2-bs3-modal

Angular Bootstrap 3 Modal Component
http://dougludlow.github.io/ng2-bs3-modal/
ISC License
261 stars 133 forks source link

404 ng2-bs3-modal/ng2-bs3-modal not found #9

Closed nickhod closed 8 years ago

nickhod commented 8 years ago

I'm using Angular 2 beta 8 based on the angular2-quickstart module. ng2-bs3-modal is installed in node_modules and I'm using the import given in the documentation

import {MODAL_DIRECTIVES} from 'ng2-bs3-modal/ng2-bs3-modal';

The Typescript compiler can find the module however it results in a 404 with the browser trying to access http://devapp/ng2-bs3-modal/ng2-bs3-modal

Similar import directive lines such as

import {ROUTER_DIRECTIVES} from 'angular2/router';

work fine. Am I missing something in System.config?

dougludlow commented 8 years ago

@nickhod yes, you need to include a mapping to ng2-bs3-modal in the System.config so that SystemJS knows how to load it. Something like the following:

System.config({
    ...
    map: {
        'ng2-bs3-modal': 'node_modules/ng2-bs3-modal'
    }
    ...
});

Alternatively, you can include a script reference before the System.config:

<script src="node_modules/ng2-bs3-modal/bundles/ng2-bs3-modal.js"></script>
dougludlow commented 8 years ago

@nickhod were you able to get it working?

I've add those details to the readme.

nickhod commented 8 years ago

Adding the script reference before System.config worked. For whatever reason using SystemJS map didn't work (even though I'm using SystemJS), it still 404s.

dougludlow commented 8 years ago

Here's a working example of how I load it using SystemJS. The order that you load the scripts in is important:

<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.33.3/es6-shim.min.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.6/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/tools/system.js"></script>

<script>
    System.config({
        defaultJSExtensions: true, 
        globalEvaluationScope: false,
        map: {
            'ng2-bs3-modal': 'node_modules/ng2-bs3-modal'
        }
    });
</script>

<script src="https://code.angularjs.org/2.0.0-beta.6/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.6/angular2.dev.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>

<script>System.import('app/main').then(null, console.error.bind(console));</script>
lsiden commented 8 years ago

I am having the same problem, but I configured my app with Angular-Cli.

I installed ng2-bs3-modal. In my app directory, I can do:

$ ls node_modules/ng2-bs3-modal/ng2-bs3-modal.js
node_modules/ng2-bs3-modal/ng2-bs3-modal.js

Here is a snippet from my app/system-config.ts

/*** * User Configuration. *****/ /* Map relative paths to URLs. */ const map: any = { 'ng2-bs3-modal': 'node_modules/ng2-bs3-modal', };

/** User packages configuration. */
const packages: any = {
  'ng2-bs3-modal': {
    defaultExtension: 'js',
    main: 'ng2-bs3-modal.js'
  }
};

[ more config ... ]

/** Type declaration for ambient System. */
declare var System: any;

// Apply the CLI SystemJS configuration.
System.config({
  defaultJSExtensions: true,
  globalEvaluationScope: false,
  map: {
    '@angular': 'vendor/@angular',
    'rxjs': 'vendor/rxjs',
    'main': 'main.js'
  },
  packages: cliSystemConfigPackages
});

// Apply the user's configuration.
System.config({ map, packages });

In one of my app's files:

import { MODAL_DIRECTIVES, ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal';

Chromium Console says:

zone.js:101 GET http://localhost:4200/node_modules/ng2-bs3-modal/ng2-bs3-modal.js 404 (Not Found)

I'm new to Angular2 and Typescript, so I'm sure I am missing something.

mhawila commented 7 years ago

@lsiden did you manage to make this work? It is driving me nuts!

dougludlow commented 7 years ago

@mhawila I have a working angular-cli demo here: https://github.com/dougludlow/ng2-bs3-modal-demo-angular-cli, if it helps.

mhawila commented 7 years ago

Thanks @dougludlow, unfortunately I am using angular2-seed (https://github.com/mgechev/angular-seed).

It is strange this happens only when I try to run the tests but when I ran the app with npm start it runs just fine!

dougludlow commented 7 years ago

@mhawila if you want to open a new issue and provide some more details, I'd be more than happy to do some troubleshooting with you.

mhawila commented 7 years ago

@dougludlow thanks for your offer. I had to use the below configuration

map: {
    'ng2-bs3-modal': 'ng2-bs3-modal/bundles'
  },
  meta: {
    'ng2-bs3-modal': {
      format : 'register'
    }
  }

It seems systemjs was not able to resolve the type of module being loaded. For anyone using the seed I added this in the file test-config.js. The whole file is below

// Load our SystemJS configuration.
System.config({
  baseURL: '/base/',
  map: {
    'ng2-bs3-modal': 'ng2-bs3-modal/bundles'
  },
  meta: {
    'ng2-bs3-modal': {
      format : 'register'
    }
  }
});

Warning ๐Ÿ‘† ๐Ÿ‘† stuff does not work because for some reason the bundled version is not loaded correctly by systemjs

Update I added the following lines to the karma.config.js to make the files available to karma.files map. I am not so familiar with karma but I assume that is where the karma web server serves the files from (I have to learn more about karma I guess ๐Ÿ˜ƒ )

module.exports = function(config) {
    config.set({
        // Other things
        files: [
            // list of files
            ...
           'node_modules/jquery/dist/jquery.min.js',
            { pattern: 'node_modules/ng2-bs3-modal/components/*.js', included: false, watched: false },
            { pattern: 'node_modules/ng2-bs3-modal/directives/*.js', included: false, watched: false },
            { pattern: 'node_modules/ng2-bs3-modal/ng2-bs3-modal.js', included: false, watched: false   },
             // More stuff
         ],
    });
   // More stuff
};

By the way importing the module with another names causes the test to fail too. I don't know why, so instead of import { SomeOtherName } from 'ng2-bs3-modal/ng2-bs3-modal' use import { Ng2Bs3Module } from 'ng2-bs3-modal/ng2-bs3-modal'

Nobody84 commented 7 years ago

@nickhod & @dougludlow I got the same error today and a recognized that my app wants to load http://localhost:3000/node_modules/ng2-bs3-modal/ng2-bs3-modal instead of http://localhost:3000/node_modules/ng2-bs3-modal/ng2-bs3-modal.js

Then I set the default extension for ng2-bs3-modal to .js and it worked for me. Here the importand lines of my systemjs.contig.js packages: { ... 'ng2-bs3-modal': { defaultExtension: 'js' }, ... }

nguni52 commented 7 years ago

Thank you.

I had done the same, as I had noticed it wasn't loading as expected, and it loaded.

Cheers,

Nguni Phakela Twitter: @nguni52 Cell: 061-131-2053 Sent from my iPhone6 Plus

On 30 Oct 2016, at 4:42 PM, Nobody84 notifications@github.com wrote:

@nickhod & @dougludlow I got the same error today and a recognized that my app wants to load http://localhost:3000/node_modules/ng2-bs3-modal/ng2-bs3-modal instead of http://localhost:3000/node_modules/ng2-bs3-modal/ng2-bs3-modal.js

Then I set the default extension for ng2-bs3-modal to .js and it worked for me. Here the importand lines of my systemjs.contig.js

packages: { ... 'ng2-bs3-modal': { defaultExtension: 'js' }, ... }

โ€” You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

lirongfei123 commented 7 years ago

How TypeScript resolves modules

TypeScript will mimic the Node.js run-time resolution strategy in order to locate definition files for modules at compile-time. To accomplish this, TypeScript overlays the TypeScript source file extensions (.ts, .tsx, and .d.ts) over the Nodeโ€™s resolution logic. TypeScript will also use a field in package.json named "typings" to mirror the purpose of "main" - the compiler will use it to find the โ€œmainโ€ definition file to consult. so just add this to package.json it will ok "typings": "ng2-bs3-modal.d.ts", use this code import { Ng2Bs3ModalModule } from 'ng2-bs3-modal';

ghost commented 7 years ago

What if one is using webpack instead? Running into this error while using webpack with Angular2.

stephenad commented 7 years ago

@dougludlow

I am trying to get your modal example working in my angular 2 project but I am getting the following errors when i run ng serve, I am new to Angular so if you need to see any other files please let me know.

I get these errors:

`ERROR in C:/wamp/www.../public_cli/src/app/services/dialog.service.ts (1,32): Cannot find module 'ng2-bs3-modal'.

ERROR in C:/wamp/www.../public_cli/src/app/services/dialog.service.ts (3,2): Cannot find name 'Injectable'.

ERROR in C:/wamp/www.../public_cli/src/app/services/dialog.service.ts (15,10): Property 'output' does not exist on type 'DialogService'.

ERROR in C:/wamp/www.../public_cli/src/app/services/dialog.service.ts (15,38): Property 'selected' does not exist on type 'DialogService'.

ERROR in C:/wamp/www.../public_cli/src/app/services/dialog.service.ts (19,10): Property 'output' does not exist on type 'DialogService'.

ERROR in C:/wamp/www.../public_cli/src/app/services/dialog.service.ts (23,10): Property 'output' does not exist on type 'DialogService'.

ERROR in C:/wamp/www.../public_cli/src/app/services/dialog.service.ts (27,10): Property 'router' does not exist on type 'DialogService'. `

These are my relevant files: index.html

`<!doctype html>

NGI Documents
Loading...

`

Dialog Service

`import { ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal';

@Injectable() export class DialogService {

private modal: ModalComponent;

constructor() {}

openDialog(modalComponent: any): void { this.modal.open(); }

closed() { this.output = '(closed) ' + this.selected; }

dismissed() { this.output = '(dismissed)'; }

opened() { this.output = '(opened)'; }

navigate() { this.router.navigateByUrl('/hello'); }

}`

my manageuser.component.html

` <button type="button" class="btn btn-default" (click)="modal.open()">Open me!

Output

{{ output }}

Selected: {{ selected }}

I will navigate to another route when you close the modal.

Note: My z-index is set to 1049.

` my manageuser.component.ts file: ` /* !!! System Imports !!! */ import { Component, OnInit, OnDestroy } from '@angular/core'; import { FormGroup, FormControl, Validators } from '@angular/forms'; import { ToasterService } from 'angular2-toaster'; import 'rxjs/Rx'; import { ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal'; /* *** Project Imports *** */ import { ManageUserService, AppMessagingService, RenewalOptionsService, DialogService} from '../../../services/index'; import { ManageUser, NewUserInfo } from '../../../models/index'; /* ADS TO BE REMOVED IN DUE COURSE */ //import { } from '../../../services/app-messaging.service'; // import { } from '../../../services/renewal-options.service'; // import { UserAuthService } from '../../../services/user-auth.service'; /* ADS TO BE REMOVED IN DUE COURSE END*/ @Component({ selector: 'manageuser', templateUrl: './manageuser.component.html', }) export class ManageUserComponent implements OnInit, OnDestroy { myForm: FormGroup; loading: boolean; userlist: ManageUser[]; selectedUser = this.userlist; checkexistanceuserlist = this.userlist; title: string; message: string; confirmResult:boolean = null; beingdeleted: boolean = false; beingreset: boolean = false; userexists: boolean = false; u_id: number = 0; u_email: string; u_firstname: string; u_lastname: string; u_company: string; u_businesstype: string; u_mailinglist: string; u_status: string; u_admin:string; u_username: string; modal: ModalComponent; items: string[] = ['item1', 'item2', 'item3']; selected: string; output: string; // model: Person = new Person(); css: boolean = false; index: number = 0; cssClass: string = ''; animation: boolean = true; keyboard: boolean = true; backdrop: string | boolean = true; backdropOptions = [true, false, 'static']; //userexistance = []; constructor( private aMS: AppMessagingService, private manageuserService: ManageUserService, private toasterService: ToasterService, private dialogService: DialogService, private renewalOptionsService: RenewalOptionsService ) { } closed() { alert('you are in closed'); this.output = '(closed) ' + this.selected; } dismissed() {alert('you are in dismissed'); this.output = '(dismissed)'; } opened() {alert('you are in opened'); this.output = '(opened)'; } open() { alert('you are in OPEN'); this.modal.open(); } ` package.json `{ "name": "ngi-app", "version": "2.0.0", "license": "MIT", "angular-cli": {}, "scripts": { "start": "ng serve", "lint": "tslint \"src/**/*.ts\"", "test": "ng test", "pree2e": "webdriver-manager update", "e2e": "protractor" }, "private": true, "dependencies": { "@angular/common": "2.3.1", "@angular/compiler": "2.3.1", "@angular/core": "2.3.1", "@angular/forms": "2.3.1", "@angular/http": "2.3.1", "@angular/platform-browser": "2.3.1", "@angular/platform-browser-dynamic": "2.3.1", "@angular/router": "3.3.1", "@ng-bootstrap/ng-bootstrap": "1.0.0-alpha.22", "@types/file-saver": "0.0.1", "@types/jspdf": "1.1.31", "@types/lodash": "4.14.50", "@types/xlsx": "0.0.34", "angular-datatables": "2.3.0", "angular2-cookie": "^1.2.5", "angular2-select": "1.0.0-beta.3", "angular2-toaster": "3.0.1", "body-parser": "1.17.1", "bootstrap": "^3.3.7", "chart.js": "^2.4.0", "child_process": "1.0.2", "core-js": "^2.4.1", "datatables.net": "1.10.13", "datatables.net-dt": "1.10.13", "file-saver": "1.3.3", "https": "1.0.0", "jquery": "3.2.1", "json2csv": "3.7.3", "jspdf": "1.3.3", "jspdf-autotable": "2.3.2", "jw-bootstrap-switch-ng2": "^1.0.4", "lodash": "4.17.4", "moment": "2.18.1", "moment-timezone": "0.5.13", "multer": "1.3.0", "mysql": "2.13.0", "ng2-bootstrap": "1.6.1", "ng2-bootstrap-modal": "^1.0.1", "ng2-bs-dropdown": "0.7.0", "ng2-bs3-modal": "^0.10.4", "ng2-charts": "1.4.1", "ng2-datepicker": "1.8.3", "ng2-file-upload": "1.1.4-2", "ng2-pagination": "1.0.1", "ng2-slimscroll": "1.3.2", "ng2-toastr": "1.3.2", "ng2-validation": "3.9.1", "ng2-validators": "2.1.1", "node-cron": "1.1.3", "nodemailer": "4.0.1", "rand-token": "0.3.0", "rxjs": "5.3.0", "swig": "1.4.2", "tls": "0.0.1", "ts-helpers": "^1.1.1", "ts-xlsx": "0.0.11", "typings": "^2.0.1", "zone.js": "0.7.2" }, "devDependencies": { "@angular/compiler-cli": "2.3.1", "@types/datatables.net": "1.10.1", "@types/jasmine": "2.5.38", "@types/jquery": "2.0.41", "@types/moment": "2.13.0", "@types/moment-timezone": "0.2.34", "@types/node": "^6.0.42", "angular-2-dropdown-multiselect": "1.0.8", "angular-cli": "1.0.0-beta.28.3", "codelyzer": "2.0.0-beta.1", "jasmine-core": "2.5.2", "jasmine-spec-reporter": "2.5.0", "karma": "1.2.0", "karma-chrome-launcher": "2.0.0", "karma-cli": "1.0.1", "karma-jasmine": "1.0.2", "karma-remap-istanbul": "0.2.1", "nodemon": "1.11.0", "protractor": "4.0.13", "ts-node": "1.2.1", "tslint": "4.3.0", "typescript": "2.0.3", "typings": "^2.0.1", "webdriver-manager": "10.2.5", "webpack": "^3.4.1" } } ` Thanks in advance for any advice or assistance. Andy