Question: How to write a function which will be return : Observable .

my service:

```
 modelTemp= [{ 
    name: 'abcdefghijk'
 }];   
 get(): Observable<ModelTemp> {
    return this.modelTemp;
 }

```

In service the method the variable is displayed red:

*Returned expression type {name: string}[] is not assignable to type Observable less... (Ctrl+F1) 
Checks TypeScript called function parameters , return values , assigned expressions to be of correct type*

How to fix this error?

my component:

```
 model: ModelTemp; 

    constructor(private getService: GetService) {}
    ngOnInit() {
      this.generate();
    }

    generate() {
      this.getService.get()
        .subscribe((modelData) => { 
          this.model = modelData;
        });
    }

```

my interface:

```
   export interface ModelTemp {
      name: string; 
   }

```

I do not know where I'm making a mistake. The model component should be declared differently (in this way):
 modelPage: ModelPage;
or so:
 modelPage: ModelPage[];

In my the browser returns me an error:

*this.getService.get(...).subscribe is not a function at TempComponent.push../src/app/temp/temp.component.ts.TempComponent.generate.*

I want to use the subscribe method. Which will return the model (interface ModelTemp)

How to correct the code?

How to write a function which will be return : Observable .

Answer: 
use rxjs operators like **of** to return an Observable

```
import {of} from 'rxjs';

 get(): Observable<ModelTemp> {
  return of(this.modelTemp);
} 

```
You can try something like this:

```
modelTemp: BehaviorSubject<ModelTemp[]> = new BehaviorSubject([{ 
    name: 'abcdefghijk'
}]);

get(): BehaviorSubject <ModelTemp[]> {
    return this.modelTemp;
}

```

This returns a Subject that you can subscribe to.