2016-01-07 13 views
5

Sto usando angualr-material e voglio passare un parametro a $mdToast.show() all'interno del controller, ho verificato che c'è un ambito nella funzione ma non so come codificarlo, ho provato molte espressioni, ma non ho funzionato, per favore aiutami, grazie mille! Ecco il mio codice:

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> 

D: Come mostrare il valore in prova per angolare?

risposta

6

Ok, ho appena scoperto che c'è un locali di utilizzare:

$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; 
    }]); 
2
$mdToast.show({ 
        locals:{parm : $scope.abdata}, 
        hideDelay : 3000, 
        position : 'top right', 
        controller : 'ToastCtrl', 
        templateUrl : 'templates/toast-template.html' 
       }); 
//controller is 
.controller('ToastCtrl', function($scope, $mdToast, $mdDialog, parm) { 
     alert(parm) 
}) 
Problemi correlati