【问题标题】:How to pass parameters to controller in $mdToast.show function with angular-material 1.0.1如何使用 angular-material 1.0.1 在 $mdToast.show 函数中将参数传递给控制器
【发布时间】:2016-01-07 12:40:42
【问题描述】:

我正在使用 angualr-material 并想将参数传递给控制器​​内部的$mdToast.show(),我检查了函数中有一个范围但我不知道如何编码,我尝试了很多表达式,但没有解决,请帮助我,非常感谢! 这是我的代码:

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>

问:如何在角度测试中显示值?

【问题讨论】:

    标签: angularjs angularjs-scope


    【解决方案1】:

    好的,我刚刚发现有一个本地人可以使用:

        $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)
      })
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-14
        相关资源
        最近更新 更多