2015-04-03 48 views
4

我試圖單擊圖標時生成對話框。當我點擊md-icon時,出現以下錯誤。對話框打開,但我在控制檯上看到以下錯誤:

TypeError: Cannot read property 'getBoundingClientRect' of undefined 
at transformToClickElement (angular-material.js:4652) 
at dialogPopIn (angular-material.js:4630) 
at Object.onShow (angular-material.js:4538) 
at InterimElementFactory.self.show.compilePromise.then.showDone (angular-material.js:1827) 
at processQueue (angular.js:13248) 
at angular.js:13264 
at Scope.$get.Scope.$eval (angular.js:14466) 
at Scope.$get.Scope.$digest (angular.js:14282) 
at Scope.$get.Scope.$apply (angular.js:14571) 
at done (angular.js:9698)        

angular-material.js:824 Uncaught TypeError: Cannot read property 'hasAttribute' of undefined 

下面是我的HTML代碼片段。

<md-button class="md-fab md-primary" ng-click="showAdvanced($event)" 
      aria-label="AddClient"> 
    <md-icon md-svg-src="content/images/68448.svg" 
      style="width: 48px; height: 48px;"> 
    </md-icon> 

    <md-tooltip md-visible="demo.showTooltip"> 
     Add Client 
    </md-tooltip> 
</md-button> 

HTML頁面的控制器如下。

$scope.showAdvanced = function(ev) { 
$mdDialog.show({ 
    controller: 'newClient', 
    templateUrl: 'app/views/xyz/newClient.html', 
    targetEvent: ev 
});}; 

對話框HTML

<md-content class="md-padding" layout="row" layout-sm="column" style="font-size:1.2em"> 
     <form name="myForm" > 
      <div layout layout-sm="column"> 
       <md-input-container style="width:80%"> 
        <label>Name</label> 
        <input ng-model="create.Name"> 
       </md-input-container> 
      </div> 
</md-content> 

感謝

回答

18

你缺少一個包裝MD-對話框標籤。根據文檔:

該對話框的模板必須有一個外部的md-dialog元素。在內部,使用md-content元素作爲對話框的內容,並使用具有類md-actions的元素作爲對話框的動作。

試試這個:

<md-dialog> 
    <md-content> 
    <md-button class="md-fab md-primary" ng-click="showAdvanced($event)" aria-label="AddClient"> 
     <md-icon md-svg-src="content/images/68448.svg" style="width: 48px; height: 48px;"></md-icon> 

     <md-tooltip md-visible="demo.showTooltip"> 
     Add Client 
     </md-tooltip> 
    </md-button> 
    </md-content> 
</md-dialog> 
+0

謝謝....我已經錯過了對話框模板的MD-對話框標籤。 – user4321 2015-04-06 14:32:36

相關問題