There is no directive with "exportAs" set to "bs-modal" - ng2-bootstrap

I would like to integrate child modal into my project following example at
https://valor-software.com/ng2-bootstrap/#/modals#static
but I got an exception showing as below:
There is no directive with "exportAs" set to "bs-modal". I searched on google and found an answer at this link but it didn't work.
https://github.com/valor-software/ng2-bootstrap/issues/667#issuecomment-235204534
This line doesn't work when I followed his solution:
import {MODAL_DIRECTIVES, BS_VIEW_PROVIDERS,ModalDirective} from 'ng2-bootstrap/ng2-bootstrap';
Anybody can help? Thanks.
My project is using:
"ng2-bootstrap": "^1.2.4"
"#angular/common": "2.4.3",
"#angular/compiler": "2.4.3",
"#angular/core": "2.4.3",
"#angular/forms": "2.4.3",
"#angular/http": "2.4.3",

I also used same modal from same link. So I got exactly the same error. The solution was for me like that:
You should add import {ModalModule} from 'ng2-bootstrap/modal' line to your
app.module.ts and then import it like below. Just make sure using forRoot().
Without it you'll keep getting error.
#NgModule({
imports: [
ModalModule.forRoot()
]
After that you need to do this import operation for yourpage.module.ts , too.
That solution worked for me, I hope for you ,too.
Note: by the way here is my versions:
"ng2-bootstrap": "^1.3.3",
"#angular/common": "2.4.8",
"#angular/compiler": "2.4.8",
"#angular/core": "2.4.8",
"#angular/forms": "2.4.8",
"#angular/http": "2.4.8",

This Kind of a problem may be caused by either of the following two scenarios:
1. You could be missing this line in your component
#ViewChild('childModal') public childModal: ModalDirective;
2. You could have omitted an import in your module declaration
import {ModalModule} from "ng2-bootstrap";
#NgModule({
imports: [
ModalModule.forRoot()
],
declarations: [],
providers: []
})
export class MyModule{}

Related

Angular 6 with UpgradeModule cant resolve all parameters for ApplicaitonModule

I have migrated and old AngularJS application to run, with Angular 5, in upgrade mode using the UpgradeModule. Everything is working I have some services migrated to Angular and utilise some more modern libs, like ngx-translate. It was all working fine. Then I updated to Angular 6 following the update guide. I fixed the rxjs issues and all imports are pointing correctly but when I stat the app I just get:
Error: Can't resolve all parameters for ApplicationModule: (?).
In the console.
This is the module part of my main.ts file:
import {NgModule} from '#angular/core';
import {HTTP_INTERCEPTORS} from '#angular/common/http';
import {HttpClientModule, HttpClient} from '#angular/common/http';
import {BrowserModule} from '#angular/platform-browser';
import {UpgradeModule} from '#angular/upgrade/static';
import { FormsModule } from '#angular/forms';
import {platformBrowserDynamic} from '#angular/platform-browser-dynamic';
import {ErrorHandler} from './components/error-interceptor/error.handler';
import {RequestInterceptor} from './components/error-interceptor/http-error-interceptor.service';
import {TranslateLoader, TranslateModule} from '#ngx-translate/core';
import {httpLoaderFactory} from './http.loader.factory';
import {uiRouterStateProvider, uiRouterStateParamsProvider} from "./ajs-upgraded-providers";
import {RestService} from './components/rest/rest.service';
import {TemplateService} from './configuration/templates/template.service';
import {ValidationService} from './components/form-validation/form-validation.service';
import {AlertService} from './components/alert/alert.service';
import {UtilService} from './app.util.service';
import {AlertComponent} from './components/alert/alert.directive';
import {TemplateCreateComponent} from './configuration/templates/modify/template-create.controller';
#NgModule({
imports: [
BrowserModule,
UpgradeModule,
HttpClientModule,
FormsModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: httpLoaderFactory,
deps: [HttpClient]
}
})
],
providers: [
RestService,
ValidationService,
AlertService,
TemplateService,
UtilService,
uiRouterStateProvider,
uiRouterStateParamsProvider,
ErrorHandler,
{
provide: HTTP_INTERCEPTORS,
useClass: RequestInterceptor,
multi: true,
}
],
declarations: [
//solid angular components need only be entered here
AlertComponent,
TemplateCreateComponent
],
entryComponents: [
//add downgraded components here and in declarations
AlertComponent,
TemplateCreateComponent
]
})
export class AppModule {
// Override Angular bootstrap so it doesn't do anything
ngDoBootstrap() {
}
}
// Bootstrap using the UpgradeModule
platformBrowserDynamic().bootstrapModule(AppModule).then(platformRef => {
console.log("Bootstrapping in Hybrid mode with Angular & AngularJS");
const upgrade = platformRef.injector.get(UpgradeModule) as UpgradeModule;
upgrade.bootstrap(document.body, ['PortalApp']);
});
This is the package.json file:
"dependencies": {
"#angular/animations": "^6.1.10",
"#angular/cli": "^6.2.9",
"#angular/common": "^6.1.10",
"#angular/compiler": "^6.1.10",
"#angular/compiler-cli": "^6.1.10",
"#angular/core": "^6.1.10",
"#angular/forms": "^6.1.10",
"#angular/http": "^6.1.10",
"#angular/platform-browser": "^6.1.10",
"#angular/platform-browser-dynamic": "^6.1.10",
"#angular/platform-server": "^6.1.10",
"#angular/router": "^6.1.10",
"#angular/upgrade": "^6.1.10",
"#ctrl/ngx-codemirror": "^1.3.10",
"#ngx-translate/core": "^10.0.2",
"#ngx-translate/http-loader": "^3.0.1",
"angular": "~1.6.10",
"angular-animate": "~1.6.10",
"angular-breadcrumb": "~0.5.0",
"angular-chosen-localytics": "~1.8.0",
"angular-clipboard": "^1.5.0",
"angular-cookies": "~1.6.10",
"angular-in-memory-web-api": "~0.5.0",
"angular-loading-bar": "~0.9.0",
"angular-messages": "~1.6.10",
"angular-moment-picker": "^0.10.2",
"angular-sanitize": "~1.6.10",
"angular-touch": "~1.6.10",
"angular-translate": "~2.18.1",
"angular-translate-loader-url": "~2.18.1",
"angular-translate-storage-cookie": "~2.18.1",
"angular-translate-storage-local": "~2.18.1",
"angular-ui-grid": "~4.8.1",
"angular-ui-router": "~1.0.22",
"angular-ui-sortable": "0.14",
"bootstrap": "^4.3.1",
"chosen-js": "~1.8.7",
"codemirror": "^5.49.2",
"core-js": "^2.6.11",
"jquery": "~2.2.4",
"jquery-ui": "~1.12.1",
"moment": "~2.24.0",
"ng-csv": "~0.3.6",
"ng-file-upload": "~12.2.13",
"ng-ui-router-state-events": "^1.0.1",
"popper.js": "^1.15.0",
"rxjs": "6.0.0",
"rxjs-compat": "6.2.2",
"selectize": "~0.12.6",
"tslint": "~5.0.0",
"typescript": "~2.7.2",
"typings": "^2.1.1",
"ui-bootstrap4": "~3.0.6",
"web-animations-js": "^2.3.1",
"webpack-cli": "^3.3.9",
"zone.js": "^0.8.4"
}
The last thing I fixed was the ngx-translate that has a different version for Angular 5 and 6 but this has been updated and still the issue.
Any idea what might be causing the issue?
OK after a lot of searching I came across a post in the git hub issues of Angular.
I will link it because it is perfect reading as this error can be caused by a number of different issues.
For me it was the order of the imports and providers specified in the main.ts so here:
providers: [
uiRouterStateProvider,
uiRouterStateParamsProvider,
UtilService,
RestService,
ValidationService,
AlertService,
TemplateService
],
declarations: [
//solid angular components need only be entered here
AlertComponent,
TemplateCreateComponent
],
entryComponents: [
//add downgraded components here and in declarations
AlertComponent,
TemplateCreateComponent
]
for instance teh ValidationService and the AlertService both referenced the UtilService but it was below them in the imports. After changing this my issue was fixed.
This is the link to the issue, I think it is useful as this can be a good reference for future people saving them a day of searching.
angular git hub issue

Angular 1 and 2 hybrid app - "require is not defined"

I'm trying to upgrade a giant client-side app from Angular 1.x to Angular 2, and I've hit a really annoying roadblock. I've recreated the issue with a dummy, light-weight project (files pasted below), but let me just explain the problem first.
Basically, when my tsconfig.json specifies module as commonjs, I get the following error in my chrome dev console:
app.module.ts:1Uncaught ReferenceError: require is not defined
When I switch the module to system, I get the following error:
Uncaught TypeError: Invalid System.register call. Anonymous System.register calls can only be made by modules loaded by SystemJS.import and not via script tags.
And when I switch module to umd, everything works fine. But given that angular themselves suggest using commonjs, I'm concerned that umd is not the right answer. However, if I'm wrong about that and umd is perfectly fine, I'd love to hear a good explanation as to why.
Here's my code to reproduce my issue:
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
}
,
"exclude": [
"node_modules"
]
}
typings.json:
{
"globalDependencies": {
"angular": "registry:dt/angular#1.5.0+20160922195358",
"core-js": "registry:dt/core-js#0.0.0+20160725163759",
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
"jquery": "registry:dt/jquery#1.10.0+20160929162922",
"node": "registry:dt/node#6.0.0+20160909174046"
}
}
systemjs.config.js :
(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/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-dynamic': 'npm:#angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'#angular/ ': 'npm:#angular/http/bundles/http.umd.js',
'#angular/router': 'npm:#angular/router/bundles/router.umd.js',
'#angular/forms': 'npm:#angular/forms/bundles/forms.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
'angular-in-memory-web-api': {
main: './index.js',
defaultExtension: 'js'
}
}
});
})(this);
package.json :
{
"name": "mattsApp",
"version": "0.0.1",
"dependencies": {
"angular": "^1.5.8",
"#angular/common": "~2.0.2",
"#angular/compiler": "~2.0.2",
"#angular/core": "~2.0.2",
"#angular/forms": "~2.0.2",
"#angular/http": "~2.0.2",
"#angular/platform-browser": "~2.0.2",
"#angular/platform-browser-dynamic": "~2.0.2",
"#angular/router": "~3.0.2",
"#angular/upgrade": "~2.0.2",
"angular-in-memory-web-api": "~0.1.5",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.8",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.39",
"zone.js": "^0.6.25"
},
"devDependencies": {
"concurrently": "^3.0.0",
"lite-server": "^2.2.2",
"typescript": "^2.0.3",
"typings":"^1.4.0"
},
"scripts": {
"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"
}
}
app.js :
angular.module('app', []);
app.module.ts :
import { NgModule } from '#angular/core';
import { BrowserModule } from '#angular/platform-browser';
import { upgradeAdapter } from './upgrade_adapter';
#NgModule({
imports: [ BrowserModule ]
})
export class AppModule { }
upgradeAdapter.bootstrap(document.body, ['app'], {strictDi: true});
appCtrl.ts :
angular.module('app')
.controller('appCtrl', ['$scope', function($scope) {
$scope.hello = "howdy worldy";
}]);
upgrade_adapter.ts :
import { UpgradeAdapter } from '#angular/upgrade';
import {AppModule} from "./app.module";
export const upgradeAdapter = new UpgradeAdapter(AppModule);
What am I missing?
you need instantiate the UpgradeAdapter with a non null parametter. In this way you need pass a forwardRef instance, something like this:
const upgradeAdapter = new UpgradeAdapter(forwardRef(() => AppModule));
finally you need import the forwardRef
import {NgModule, forwardRef} from '#angular/core';
First, thanks Andres. I need to read up a bit about the forwardRef to understand what that does. But it turns out that the answer in my particular case was something different.
I didn't post my index.html here (simple oversight), but the problem was that I wasn't loading my modules with the System.import('app'). Embarrassing error, I have to admit. So the answer is to add that line.
I should note that this led to a different error which I solved, but I'll point it out here in case others have a similar issue. Since this is a hybrid angular 1 and 2 app, I have typescript files that are sometimes used by angular 1 controllers / directives / etc, and also by angular 2 components. I had changed those typescript files to use export so I could import them into my angular 2 components. This led me to also change my /// in the angular 1 files to use import. Unfortunately, this gave me an "undefinedModule" error. The solution (in my case) is not to use export on typescript files unless they are ONLY used with the angular 2 components. Meaning, in some angular 2 components, I'm actually using the /// and not the import.
Just thought other people might find that useful.

Using Github's Node-Trello in Ionic 2 - Error TS2304: Cannot find name 'require'

newbee to ionic2, angular2 and programmatic access to Trello.
I would like to use this wrapper in ionic, but can't declare the node-trello module.
I have installed node-trello:
npm install node-trello --save
which updated my package.json:
Please see dependencies section of my package.json "node-trello" has version "^1.1.2"
{
"dependencies": {
"#angular/common": "2.0.0-rc.3",
"#angular/compiler": "2.0.0-rc.3",
"#angular/core": "2.0.0-rc.3",
"#angular/http": "2.0.0-rc.3",
"#angular/platform-browser": "2.0.0-rc.3",
"#angular/platform-browser-dynamic": "2.0.0-rc.3",
"es6-shim": "^0.35.0",
"ionic-angular": "2.0.0-beta.10",
"ionic-native": "1.2.4",
"ionicons": "3.0.0",
"minimatch": "^3.0.2",
"node-trello": "^1.1.2",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"trello": "^0.5.1",
"zone.js": "^0.6.12"
}
}
Have tried as the author says on his website
var Trello = require("node-trello");
But I get the following error despite the fact that /node-modules/node-trello directory exists.:
TypeScript error: C:/workspace/.......etc...../Service.ts(26,22): Error TS2304: Cannot find name 'require'.
You are using typescript, so it should be
import Trello = require("node-trello");
or
import * as Trello from "node-trello";
EDIT: this should work at runtime, if your modules are being loaded correctly, however it will still show an error during compilation. To get rid of the error, you have to provide typescript with the module declarations.
Normally you would download the declarations from npm or Typings, but I didn't find them for the node-trello package, so you have to provide your own.
You can put this into your declarations file:
declare module "node-trello" {
const value: any;
export default value;
}

Angular Meteor Socially Tutorial - Getting a blank page when trying to add Maps

I am just starting off with Angular Meteor NodeJS, I am quite new to these topics.
The tutorial is awesome! Things were going smooth until I updated the code to have maps related code (step 16 in the tutorial http://www.angular-meteor.com/tutorials/socially/angular2/google-maps), the application stopped working and I just see a blank screen at http://localhost:3000
I see the below message on the command line (Windows) when the application is starting:
client/imports/party-details/party-details.ts (10, 9): Module '"node_modules/angular2-google-maps/core/index"' has no exported member 'ANGULAR2_GOOGLE_MAPS_DIRECTIVES'.
client/app.ts (9, 9): Module '"node_modules/angular2-google-maps/core/index"' has no exported member 'ANGULAR2_GOOGLE_MAPS_PROVIDERS'.
Goggled the error, but couldn't gather more details on how to resolve this issue.
Is this something to do with version conflict? I am running on Windows 10.
My package.json has
{
"name": "socially",
"private": true,
"scripts": {
"start": "meteor run"
},
"dependencies": {
"#angular/common": "^2.0.0-rc.2",
"#angular/compiler": "^2.0.0-rc.2",
"#angular/core": "^2.0.0-rc.2",
"#angular/platform-browser": "^2.0.0-rc.2",
"#angular/platform-browser-dynamic": "^2.0.0-rc.2",
"#angular/router-deprecated": "^2.0.0-rc.1",
"angular2-google-maps": "^0.12.0",
"angular2-meteor": "^0.5.5",
"angular2-meteor-accounts-ui": "^0.4.3",
"angular2-meteor-auto-bootstrap": "^0.5.5",
"angular2-pagination": "^0.2.1",
"es6-shim": "^0.35.1",
"meteor-node-stubs": "~0.2.0",
"reflect-metadata": "^0.1.2",
"rxjs": "^5.0.0-beta.6",
"zone.js": "^0.6.12"
}
}
Thanks.
Ran into the same issue...
Found this: https://angular-maps.com/docs/changelog.html
ANGULAR2_GOOGLE_MAPS_PROVIDERS is now called GOOGLE_MAPS_PROVIDERS.
ANGULAR2_GOOGLE_MAPS_DIRECTIVES is now called GOOGLE_MAPS_DIRECTIVES.
in case you haven't resolved it yet.

provideRouter and RouterConfig not found in new #angular/router 3.0.0-alpha.3^

I am migrating an angular2 app to RC2 and trying to use the router's version 3 alpha.
I have followed the set up of the plunker given by the angular docs for routing
But i keep getting the following errors:
/#angular/router/index"' has no exported member 'provideRouter'
/#angular/router/index"' has no exported member 'RouterConfig'
when trying to use the following imports in my app.router.ts file:
import { provideRouter, RouterConfig } from '#angular/router';
I am using typescript in visual studio with commonjs module format.
Here are the dependecies from my packages.json
"#angular/common": "2.0.0-rc.2",
"#angular/compiler": "2.0.0-rc.2",
"#angular/core": "2.0.0-rc.2",
"#angular/http": "2.0.0-rc.2",
"#angular/platform-browser": "2.0.0-rc.2",
"#angular/platform-browser-dynamic": "2.0.0-rc.2",
"#angular/router": "3.0.0-alpha.3",
"#angular/router-deprecated": "2.0.0-rc.2",
"#angular/upgrade": "2.0.0-rc.2",
"systemjs": "0.19.27",
"core-js": "^2.4.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"angular2-in-memory-web-api": "0.0.12"
Even if I set the angular/route to the npm cdn in my system.config.js like so:
'#angular/router': 'https://npmcdn.com/#angular/router#3.0.0-alpha.3'
I still get the error.
I even tried using the alpha.4, alpha.5 and latest alpha.6 version.
I tried deleting the nodule module folder and forcing the npm install to get new files.
QUESTION:
Can someone help me figure out why the exported memebers provideRouter, RouterConfig can not be found?
Thanks
I had the same issue, solved it with using Version 3.0.0-alpha.7
Here my package.json:
"dependencies": {
"#angular/common": "2.0.0-rc.2",
"#angular/compiler": "2.0.0-rc.2",
"#angular/core": "2.0.0-rc.2",
"#angular/http": "2.0.0-rc.2",
"#angular/platform-browser": "2.0.0-rc.2",
"#angular/platform-browser-dynamic": "2.0.0-rc.2",
"#angular/router": "3.0.0-alpha.7",
"#angular/upgrade": "2.0.0-rc.2",
"systemjs": "0.19.31",
"core-js": "^2.4.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"zone.js": "^0.6.12",
"angular2-in-memory-web-api": "0.0.12",
"bootstrap": "^3.3.6",
"contentful": "3.3.14"}
Altough I wouldn't call it stable and the new Documentation https://angular.io/docs/ts/latest/guide/router.html can be bit missleading.
Try to use provideRoutes instead of provideRouter
import {provideRoutes} from "#angular/router";
and your routing:
provideRoutes([
{path: '', redirectTo: '/myurl'}
])
UPD
For now you don't need provideRouters at all. Just write path and import
Routes from '#angular/router';
import {RouterModule, Routes} from '#angular/router';
const APP_ROUTES: Routes = [
{path: '', redirectTo: '/somthng', pathMatch: 'full'},
{path: 'somthng', component: SomthngComponent},
{path: 'somthng-list', component: SomthngListComponent}
];
export const your_routing = RouterModule.forRoot(APP_ROUTES);
Also wrestled with this for a few hours, upgraded to beta7. Remember to change system.config.js as they changed packagenames to index.js (e.g. "platform-browser-dynamic/platform-browser-dynamic.js" is now named "platform-browser-dynamic/index.js".
But now I can't seem to get a default route to work, is it ''?
EDIT: Default routing is simply:
{
path: '',
redirectTo: 'index.php/component/atkstat/dashboard'
},
You need to add this line as #angular/router No umd for router yet
packages['#angular/router'] = { main: 'index.js', defaultExtension: 'js' };
Have a look package.json and system.config.js of this is , may help you
http://plnkr.co/edit/y31K7xbiQSVH59qsAOZF?p=preview

Resources