Try to search your question here, if you can't find : Ask Any Question Now ?

How to subscribe the change value of state in reduce angular 7

HomeCategory: stackoverflowHow to subscribe the change value of state in reduce angular 7
Avatarjulie asked 4 months ago

I am using redux with angular 7. I am able to add the value to the state. But how can I subscribe the change value of the state.

Here is the code that I tried

@Component({
  selector: 'app-sports-practice',
  templateUrl: './sports-practice.component.html',
  styleUrls: ['./sports-practice.component.scss']
})
export class SportsPracticeComponent implements OnInit {
  @select('ProfessionalLearningTeachers') ProfessionalLearningTeachers$: Observable<any>

  constructor(private fb: FormBuilder, private professionalLearningService: ProfessionalLearningService) {
    console.log(this.ProfessionalLearningTeachers$);
   }

  ngOnInit() {  }

}

Here is my reducer component

const meta: any = '';
const ProfessionalLearningTeachers: any = '';
const INITIAL_STATE: any = {
  meta,
  ProfessionalLearningTeachers
}
export function ProfessionalLearningTeacherReducer() {
  return function entityReducer(
    state: any = INITIAL_STATE,
    a: Action,
  ): any {
    const action = a as EntityAPIAction;
    if (!action.meta) {
      return state;
    }
    let itemIndex = -1;

    switch (action.type) {
      case ProfessionalLearningTeacherApiActions.PROFESSIONAL_LEARNING_TEACHER_SAVE_SUCCEEDED:
        return storeProfessionalLearning(state, action);
    }
    return state;
  };
}

function storeProfessionalLearning(state, action): any {
  return Object.assign({}, state, {
    meta: action.meta,
    ProfessionalLearningTeachers: action.payload,
  });
}

The state diagram

state diagram

Output of console

anonymous

reference

In angular (v5) how do I listen to my apps Redux state object changing?

https://github.com/angular-redux/store/blob/master/articles/select-pattern.md

1 Answers
Best Answer
AvatarArben answered 4 months ago
Your Answer

1 + 4 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com