I'm trying to make 2tabs app using routeProvider ng-view and 2 controllers.At first tab would be user form. At second tab i want to show back to user what he entered with validation messages.
routing
project.config(["$routeProvider",function($routeProvider)
{
$routeProvider.
when('/', {controller:'Ctrl1', templateUrl:'tab_1.html'}).
when('/tab1', {controller:'Ctrl1', templateUrl:'tab_1.html'}).
when('/tab2', {controller: 'Ctrl2', templateUrl:'tab_2.html'}).
To store data i use factory
project.factory('userService', function(){
return{valids: {}}
})
and call it on my 2 cntrollers
project.controller('Ctrl1', ['$scope', '$rootScope', 'userService', function(scope, rootScope, userService){
scope.data=userService;
And assign variables on controller html template
ng-model="data.input1"
After page(tab1) is loaded i have access to $dirty and $invalid values of my input.
scope.form.input.$invalid;
But when user switches to tab2 as i understand controller1 flushes, and i now ave only factory data and some vars that is send manually using $on('$routeChangeStart' function
The question is - what is the best and correct way to store/send/share these $dirty and invalid variables, to have access to them in second controller? How to do it angular way?
Mb i need add them to factory data like so
scope.data.valids.input_invalid = scope.form.input.$invalid;
scope.data.valids2.input_invalid = scope.form.input2.$invalid;
Or add some controller(factory/directive?)?
Or manually write validation function(controller/factory/directive?) on controller2/2 scope?