0

I display some "courses" in a list by assign all courses to angular var and use ng-repeat to show all "courses". When user click on "course" the application need to load a view (by using ng-view and angular routing) and to display a templateURL that use the clicked course data.

What i did is when user click on course, i invoke a function that assign the course data to an angular var ($scope.selectedCourse = course) and then change the url path ($location.path('courseView')). The 'courseView' should use the 'selectedCourse' data and to display the course.id , course.name etc.

What happens is that i get the courseView but without the 'selectedCourse' data. How it can work or what is a better way to click on course and to display a courseView with the selected object data?

1
  • If you use different controller for those two views you have to pass selectedCourse when you change URL Commented May 19, 2018 at 13:52

1 Answer 1

0

Main idea is extract data to the separate service and user resolve route patter.

  1. Create a service where all your courses will live.
  2. Use this service inside the first controller to render the list of courses
  3. When user click on a course, extract course id or smth similar and pass it to the routing like this: /courseview/12
  4. Modify your routing to use resolve section and get concrete course from the service mentioned at the p.1
  5. Use the course in the second controller/

Here you can read more about resolve route pattern

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.