Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameters to controller in $mdToast.show function with angular-material 1.0.1

I'm using angualr-material and want to pass a parameter to $mdToast.show() inside controller, I checked out there is a scope in the function but I don't know how to code it, I tried lots of expressions, but not working out, please help me, thanks a lot! Here is my code:

Js:

var test='test for angular';
$mdToast.show({
   templateUrl: 'TemplateView/CustomToast/warning.html',
   controller: 'WarningToastCtrl',
   scope:test 
});

angular.module('app')
   .controller('WarningToastCtrl', ['$scope', function ($scope) {
       $scope.value=test;
   }]);

Html:
<md-toast class="warning-toast">
    <span flex>{{value}}</span>
</md-toast>

Q: How to show the value into test for angular?

like image 569
Conan Lee Avatar asked Jan 07 '16 12:01

Conan Lee


1 Answers

Ok, I just found out there is a locals to use:

    $mdToast.show({
      templateUrl: 'TemplateView/CustomToast/warning.html',
      controller: 'WarningToastCtrl',
      locals:{parm:test} 
    });
    angular.module('app')
.controller('WarningToastCtrl', ['$scope', 'parm', function ($scope, parm) {
        $scope.showValue = parm;
    }]);
like image 57
Conan Lee Avatar answered Nov 15 '22 05:11

Conan Lee