I just updated angular-cli (v1.1) and created a new project using ng new MyProj.
Then I added and installed two dependencies to the project.json file:
"dependencies": {
...
"toastr": "2.1.2",
"spin": "0.0.1"
},
"devDependencies": {
...
"@types/toastr": "2.1.32",
"@types/spin": "2.3.30",
...
"typescript": "~2.3.3"
}
Then I updated the autogenerated app.component.ts adding this constructor:
constructor() {
toastr.success('Hi')
}
The IDE (visual studio code) do not return any error but when I serve the application using ng serve I get the following error:
ERROR in ../A/src/app/app.component.ts (15,5): C annot find name 'toastr'.
I really cannot figure out what is wrong with that.
Thanks a lot
-
have you install this dependencies using npm install command?Mahesh Singh Chouhan– Mahesh Singh Chouhan2017年06月07日 19:36:32 +00:00Commented Jun 7, 2017 at 19:36
-
also in angular you need to import and inject your npm modules first, follow angular2-toastr documentation for more infoMahesh Singh Chouhan– Mahesh Singh Chouhan2017年06月07日 19:39:58 +00:00Commented Jun 7, 2017 at 19:39
-
Yes, I did use npm install. I'm not using Angular2.toastr. I'm just using the "original" js library, so it is not a module, it is just a js file.user3471528– user34715282017年06月08日 05:01:50 +00:00Commented Jun 8, 2017 at 5:01
-
if it is only js library then you need to include js and css in index.html file, then you can use toaster inside any component, without including it would not workMahesh Singh Chouhan– Mahesh Singh Chouhan2017年06月08日 14:43:24 +00:00Commented Jun 8, 2017 at 14:43
-
I have the same problem, are there any updates by now? :(jlang– jlang2017年08月21日 10:35:06 +00:00Commented Aug 21, 2017 at 10:35
2 Answers 2
I solved the problem removing types from tsconfig.app.json.
This is the new configuration:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"baseUrl": ""
},
"exclude": [
"test.ts",
"**/*.spec.ts"
]
}
Comments
Try doing import * as toastr from 'toastr' or import toastr from 'toastr' - the latter is if it has a default export.