Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$mdDialog: locals not working! #455

Closed
aozora opened this issue Oct 20, 2014 · 11 comments
Closed

$mdDialog: locals not working! #455

aozora opened this issue Oct 20, 2014 · 11 comments

Comments

@aozora
Copy link

@aozora aozora commented Oct 20, 2014

Hi,
The locals option for $mdDialog service is not working: how to pass objects to the dialog scope?

@rschmukler

This comment has been minimized.

Copy link
Contributor

@rschmukler rschmukler commented Oct 20, 2014

Locals injects things into the controller, not onto the scope.

mdDialog.show({locals: { name: 'Bob' }, controller: 'myController'});

module.controller('myController', function($scope, name) {
  $scope.name = name;
});
@rschmukler rschmukler closed this Oct 20, 2014
@ajoslin

This comment has been minimized.

Copy link
Contributor

@ajoslin ajoslin commented Oct 21, 2014

You can also do it a bit more conveniently inline:

$mdDialog.show({
  locals: { name: 'Bob' },
  controller: ['$scope', 'name', function($scope, name) { 
    $scope.name = name;
  }]
});
@aozora

This comment has been minimized.

Copy link
Author

@aozora aozora commented Oct 21, 2014

Cool!
thanks!

@thallukrish

This comment has been minimized.

Copy link

@thallukrish thallukrish commented Jan 6, 2015

Thanks, a bit that can be easily overlooked looking at the example.

Why do we have such roundabout way of passing parameters to mdDialog.show?

@jadjoubran

This comment has been minimized.

Copy link
Contributor

@jadjoubran jadjoubran commented Jun 19, 2015

Because it has an isolated scope.

"The dialog is always given an isolate scope." from https://material.angularjs.org/latest/#/api/material.components.dialog/service/$mdDialog

@gkalpak

This comment has been minimized.

Copy link
Member

@gkalpak gkalpak commented Jun 22, 2015

This isn't 100% accurate. You can pass your own scope (but if you don't then a new isolate scope will be created and used).

@assaftenen

This comment has been minimized.

Copy link

@assaftenen assaftenen commented Jan 11, 2016

What about passing scope data from the dialog into the parent one?

@Vijay1990

This comment has been minimized.

Copy link

@Vijay1990 Vijay1990 commented Jun 13, 2016

cool!
Work like a charm!!

@ViruSzZ

This comment has been minimized.

Copy link

@ViruSzZ ViruSzZ commented Jun 15, 2016

Hello,

I'm not sure whether I'm doing something wrong but locals aren't working for me. I have the following:

   <md-button ng-click='listObjects.viewDetailsDialog($event, object)'>

and also this

    this.viewDetailsDialog = (ev, obj) => {
        $mdDialog.show({
          templateUrl: 'client/objects/list-objects/view-details.dialog.html',
          clickOutsideToClose: true,
          openFrom: {top: -50, width: 30, height: 80},
          closeTo: {left: 500},
          preserveScope: true,
          targetEvent: ev,
          locals: { item: obj }
        });
      }

the obj object isn't passed to view-details.dialog.html. Any thoughts what I'm doing wrong?


EDIT:

Ok, I've just got it working by changing the viewDetailsDialog method to:

    this.viewDetailsDialog = (ev, obj) => {
        $mdDialog.show({
          templateUrl: 'client/objects/list-objects/view-details.dialog.html',
          clickOutsideToClose: true,
          openFrom: {top: -50, width: 30, height: 80},
          closeTo: {left: 500},
          preserveScope: true,
          targetEvent: ev,
          locals: { item: obj },
          controller: ['$scope', 'item', function($scope, item) {
            $scope.item = item;
          }]
        });
      }
@christrude

This comment has been minimized.

Copy link

@christrude christrude commented Jun 15, 2016

3 things:

  1. you have to declare a controller for the dialog (not sure if you are doing that from this example
  2. you have to have ‘item’ in the controller dependency list ( .controller('CatalogCtrl', function ($scope, $http, $timeout, item){})
  3. you have to set ‘item’ into the scope in the controller ( $scope.item = item;)
@ThomasBurleson

This comment has been minimized.

Copy link
Contributor

@ThomasBurleson ThomasBurleson commented Jun 16, 2016

@ViruSzZ - Please look at $mdDialog Documentation to see how locals are used with controllers.

@angular angular locked and limited conversation to collaborators Jun 16, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
You can’t perform that action at this time.