2016-11-23 51 views
0

我对AngularJS非常新颖。我试图显示角度JS中弹出的模式。 我已经尝试了对角线对话框演示教程中的按钮单击模式。在页面加载时,检查一个条件并在Angular JS中弹出模态弹出

我现在需要的是,在页面加载时,应该检查一个条件,根据该条件弹出应该显示。我有个想法,喜欢在页面加载时自动点击此按钮。但我认为这不是一个好方法。我研究了各种选项,但找不到相关的解决方案。

任何帮助,可以赞赏。

以下是迄今为止从this演示中已经完成的工作。

HTML:

<div ng-controller="TestCtrl" layout="row" ng-cloak style="height: 300px"> 
    <style> 
    .edgePadding { 
    padding-left: 25px; 
    padding-right: 25px; 
    } 

</style> 
<div layout="column" layout-align="center start" layout-padding flex> 
<div class="inset"> test test test </div> 

<div class="dialog-demo-content" layout="column" layout-align="center center" style="width:100%"> 
    <md-button class="md-primary md-raised edgePadding" ng-click="openFromLeft()" > 
    test 
    </md-button> 
</div> 

app.js

angular.module('mytestapp') 

.controller('TestCtrl', function($scope, $mdDialog) { 
    $scope.openFromLeft = function() { 
    $mdDialog.show(
     $mdDialog.alert() 
     .clickOutsideToClose(true) 
     .title('Opening from the left') 
     .textContent('Closing to the right!') 
     .ariaLabel('Left to right demo') 
     .ok('Nice!') 
     // You can specify either sting with query selector 
     .openFrom('#left') 
     // or an element 
     .closeTo(angular.element(document.querySelector('#right'))) 
    ); 
    }; 

    $scope.openOffscreen = function() { 
    $mdDialog.show(
     $mdDialog.alert() 
     .clickOutsideToClose(true) 
     .title('Opening from offscreen') 
     .textContent('Closing to offscreen') 
     .ariaLabel('Offscreen Demo') 
     .ok('Amazing!') 
     // Or you can specify the rect to do the transition from 
     .openFrom({ 
      top: -50, 
      width: 30, 
      height: 80 
     }) 
     .closeTo({ 
      left: 1500 
     }) 
    ); 
    }; 
}) 

任何基本方法是赞赏。

回答

1

在你的控制器提供父DIV

<div ng-controller="TestCtrl" ng-init="loadFun()" layout="row" ng-cloak style="height: 300px"> 

的NG-INIT现在

$scope.loadFun=function(){ 
$mdDialog.show(
    $mdDialog.alert() 
    .clickOutsideToClose(true) 
    .title('Opening from offscreen') 
    .textContent('Closing to offscreen') 
    .ariaLabel('Offscreen Demo') 
    .ok('Amazing!') 
    // Or you can specify the rect to do the transition from 
    .openFrom({ 
     top: -50, 
     width: 30, 
     height: 80 
    }) 
    .closeTo({ 
     left: 1500 
    }) 
); 
}