1

I am working on a Single Page Application. Page A , Page B are partials. We have a button "btnA" on "Page A" rendered using "controllerA". At click of "btnA" we need to perform "serviceA.somework()" and at successful completion, load "Page B" using "controllerB" with some params.

Is following the best way to achieve this?

within controllerA.onClickBtnA() { $location.path(PageB).search({param:'value'})}

1
  • 1
    This is a rather open question but I can't see why this is bad? In this scenario the viewmodel/controller is the glue between all logic. Commented Sep 7, 2015 at 11:49

1 Answer 1

1

$routeProvider is the best choice for your scenario. You should not load the controller manually in any way. The Angular router does the job for you.

A simple example from the angular official API page: http://plnkr.co/edit/foLnNL7koXzUYavnYFFw?p=preview.


Update

Your proposal is basically doing what $routeProvider does. $routeProvider provides:

  1. RegExp in path definition
  2. Browsing history
  3. A resolve function to control access to current path
  4. Place to define your controller and template for each path
  5. Mechanism to deal with path parameters
  6. ...

And it is well tested and supported. You'd better have a try.

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

1 Comment

Thanks. Can you please point out what will be the major pros in this option with the cons in the one posted in the original question?

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.