0

i am new to angular js .i know about controllers,which uploads data to view.

a sample controller with my knowledge,,

angular.module('marksTotal',[]).controller('totalMarks',function($scope){
      $scope.totMarks=$scope.sub1+$scope.sub2+$scope.sub3+$scope4.sub;
      $scope.totMarks+=$scope.sub5;
      $scope.avgMarks=$scope.totMarks/5;
  }    

i have a doubt how to share data b/w different controllers in the same page & b/w different pages.

could you please clarify my doubt

thanks. ravi

  • Possible duplicate of [Angular: Share data between controllers](http://stackoverflow.com/questions/21919962/angular-share-data-between-controllers) – Szabolcs Páll Oct 21 '15 at 08:17

2 Answers2

0

The best way is to write a service for this on the long term.

But to get you startet you could put things in the $rootScope:

$rootScope.data.var = someValue

and access this values from any scope.

Andre Kreienbring
  • 2,457
  • 11
  • 16
0

You can open different pages and controllers via modal windows. I use this one. Basically you open a template and a controller in a modal window and determine the data that gets passed or returned in it. My advice is reading the Github project for more information. It is just about passing $scope variables onwards and backwards in the callbacks. Apologies if I'm not more clear. I haven't used Angular in a few months.

Example from one of mine:

$scope.domain = {};
$scope.edit = function (domain, size) {
    ModalService.showModal({
        templateUrl: '/assets/layouts/domain-edit-template.html',
        controller: 'domainsEditTemplate',
        size: size,
        inputs: {
            item: domain
      }
    })
    .then(function (modal) {
        modal.close.then(function (selectedObject) {
            if(selectedObject.save == "update") {
                console.log(selectedObject);
                domain.template_id = selectedObject.templateId.template_id;
                domain.template_name = selectedObject.templateId.name;
            } else if(selectedObject.save == 'insert') {
                selectedObject.template_name = selectedObject.templateId.name;
                selectedObject.template_id = selectedObject.templateId.template_id;
                $scope.domains.push(selectedObject);
            }
        });
    });
};

Otherwise I would suggest you learn how to use AngularJS routes to send parameters in the URL.

Rcls
  • 459
  • 4
  • 18