我有一个服务:Angular2服务的领域的问题
@Injectable()
export class MyService implements IMyService {
myServiceArray: Array<string> = ["hi", "hello", "yoyo"];
}
此项服务,更新字符串ngModel的阵列组件注入。当我尝试从组件或服务打印数组时,一切工作正常(也就是使用ngModel更新数组)。
我还@Inject在另一个1.
@Injectable()
export class AnotherService implements IAnotherService {
constructor(public myService: MyService) {
}
printValues() {
console.log(this.myService.myServiceArray);
}
}
当我调用函数printValues()这样的服务,[ “喜”, “你好”, “YOYO”]即使印刷如果我更新的值带模型的阵列!
我在做什么错?
编辑:
组件的代码如下。
@Component({
selector: 'app-root',
providers: [MyService],
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppCustomerData implements IAppCustomerData {
constructor(public myService: MyService) {
}
}
你在哪里提供服务('@Component()'或'@NgModel()')? –
我把组件的代码。 [(ngModel)] ='...'位于组件的templateUrl中。 – Nano