Deploy angular 1 service in angular 2 code using ngupgrade

I have the following service, which should be an angular 1 service;

import * as angular from 'angular';

module Services {
export class testService {
    public getMessage(): string {
        return "Message";
    }
}
}
export = Services;

var app = angular.module('services', []);
app.service("testService");

In addition, I have the following angular2 code, and I want to call testService from the following angular2 code:

import {Component, Inject, Injectable
} from '@angular/core';

import {UpgradeAdapter} from '@angular/upgrade'
import {DataStore} from '../../src/datastore';
import {testService} from '../../src/testService'
import * as angular from 'angular'

let upgradeAdapter = new UpgradeAdapter();
upgradeAdapter.upgradeNg1Provider('testService', { asToken: testService });
@Component({
  templateUrl: 'build/pages/hello-ionic/hello-ionic.html',
})
@Injectable()
export class HelloIonicPage {
  message: string;
  constructor(testService1: testService) {
    this.message = testService1.getMessage();
  }
}

The problem is that when I run the above code, it tells me that there is no provider for testService, so what am I missing here?

+4
source share

Source: https://habr.com/ru/post/1649854/


All Articles