0

I would like to create an AngularJS app in which I woud have a page containing multiple tabs. Since each tab would have a very specific business logic, I am wondering what would be the best way to achieve such a thing, knowing that I want to be able to pass through data from tab to tab. The user would have to follow a specific workflow, starting on the first tab, clicking on a button and landing on the second tab, able to see and use data he generated from the first tab, and so on.

I have come across this articles : Top 18 Most Common AngularJS Developer Mistakes which talks about controllerAs attribute. Would it be something I could use to have let's say:

  • a route provider with a main controller
  • a main view including each of my tabs' view
  • a view per tab with an associated controller
  • use controllerAs to be able to pass given shared data from a controller to another

UPDATE

Apparently it is clear that it cannot work if I do something like that:

Javascript:

angular.module('myApp').controller('FirstController', function(){
    this.myVar = "I am from FirstController";
});
angular.module('myApp').controller('SecondController', function(){
    this.myVar = "I am from SecondController";
});

HTML :

<div ng-controller="FirstController as FC">
    {{FC.myVar}}
    {{SC.myVar}}
</div>
<div ng-controller="SecondController as SC">
    {{FC.myVar}}
    {{SC.myVar}}
</div>

How could I make something like this nice and working? Or should I really have shared variables amongst the controllers provided from a MainController, wrapping these two?

Thank you for your helps.

Kind regards,

mentinet
  • 744
  • 3
  • 9
  • 23
  • try and give a look at [this link](http://toddmotto.com/digging-into-angulars-controller-as-syntax/), could be helpful – Daniele Sassoli Oct 07 '15 at 09:08
  • Hehe I was just reading it thank you. Seems like that `controllerAs` attribute helps for nested scopes, but not really in my case, does it? I must start set up a project and see by myself the issues I am encountering.. – mentinet Oct 07 '15 at 09:16
  • I think you can try an have a main controller for the tabs page, and then have a nested scope for each tab, but yes, I guess you have to try it yourself. – Daniele Sassoli Oct 07 '15 at 09:19
  • Yes, I cna't see how that should work, you have to share variable provided from a Main Controller, that's what I ment in my last comment.... – Daniele Sassoli Oct 07 '15 at 10:07

0 Answers0