0

while creating the new service using ng g s serviceName i am getting the error Expected 0 arguments, but got 1.

error image

this is my package.json

{
  "name": "rapid",
  "version": "1.1.9",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.2.0",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.11",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "@asymmetrik/ngx-leaflet": "^4.0.0",
    "@dvsl/zoomcharts": "^1.18.4",
    "@ng-bootstrap/ng-bootstrap": "^4.0.3",
    "@types/c3": "^0.6.0",
    "@types/mixpanel": "^2.14.1",
    "angular-2-dropdown-multiselect": "^1.8.1",
    "angular-confirmation-popover": "^4.2.0",
    "angular-datatables": "^6.0.0",
    "angular2-tag-input": "^1.2.3",
    "angular2-toaster": "^6.1.0",
    "aws-sdk": "^2.271.1",
    "bootstrap": "^3.3.7",
    "bootstrap-daterangepicker": "^3.0.3",
    "c3": "^0.6.6",
    "core-js": "^2.4.1",
    "crypto-js": "^3.1.9-1",
    "datatables.net": "^1.10.18",
    "datatables.net-dt": "^1.10.18",
    "file-saver": "^2.0.0",
    "jquery": "^3.3.1",
    "leaflet": "^1.3.4",
    "mixpanel-browser": "^2.28.0",
    "moment": "^2.22.2",
    "ng-multiselect-dropdown": "^0.1.9",
    "ng-recaptcha": "^4.2.1",
    "ng2-table": "^1.3.2",
    "ng2-tooltip-directive": "^2.1.6",
    "ngx-bootstrap": "^3.1.2",
    "ngx-cookie-service": "^1.0.10",
    "ngx-popover": "0.0.16",
    "ngx-tooltip": "0.0.9",
    "ngx-webstorage": "^2.0.1",
    "popper.js": "^1.14.3",
    "rxjs": "^5.5.6",
    "tslib": "^1.9.0",
    "xlsx": "^0.14.1",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.12.4",
    "@angular/cli": "^7.2.1",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@types/datatables.net": "^1.10.11",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/jquery": "^3.3.4",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^5.4.0",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }
}

by taking out the providedIn parameter from @Injectable the service works as the same or i need to modify my code to solve this error i created service by ng g s serviceName to generate the service.ts file

Santhosh
  • 810
  • 2
  • 10
  • 28

3 Answers3

0

This is the new feature in Angular 6,

I think you need to update your angular-cli globally.

Please use below commands.

  • npm install -g @angular/cli
  • npm install @angular/cli

Update package.json

  • ng update @angular/cli

Update @Angular/Core

  • ng update @angular/core
0

As mentioned by others, the providedIn syntax is new starting from Angular 6. You are using Angular 5, so this won't work. In Angular 5 you need to list your services in one of your modules. If you want a singleton service(like the one that would be created with the angular 6 syntax) you need to provide the service in your root module. This is most likely the app.module (if you used the angular cli to create the app. See also: https://angular.io/guide/singleton-services. If it doesn't need te be singleton service, I would advice to provide the service in the module where you will use it. Independent of where you decide to provide the service, it should look something like this:

@NgModule({
  imports: [.. some imports...],
  providers: [MixPanelService],
  declarations: [..some components from your module...],
  exports: [...some components that need to be available outside of your module...],
})
export class MyModule{}
Emmy
  • 3,493
  • 2
  • 16
  • 25
0

we can remove the @Injectable() arguments as below everything works fine

@Injectable()
export class MixpanelService {

  constructor() { }
}
Santhosh
  • 810
  • 2
  • 10
  • 28