2016-03-16 42 views
2

由於某種原因,我的提示對話框停止工作在我的yo angular fullstack應用程序中。

我GOOGLE了一個解決方案,告訴我更新我的角度,我做了,但它沒有解決問題。

$scope.showPrompt = function(ev, ret, value) { 
    var confirm = $mdDialog.prompt() 
    .title('Rediger ' + value) 
    .textContent('Indtast en ny værdi for: ' + value) 
    .placeholder('getValue()') 
    .ariaLabel('Ny ' + value) 
    .targetEvent(ev) 
    .ok('Accepter') 
    .cancel('Annuller'); 
$mdDialog.show(confirm).then(function(result) { 
    //setValue(result); 
}); 
}; 

每當我調用函數,我得到一個錯誤,說TypeError:$ mdDialog.prompt不是一個函數。

如果我改變對話框將.confirm並刪除佔位符它工作正常

回答

1

編輯: 在JavaScript變量函數是在運行時定義:

//This code throw an error 
getValue(); 
var getValue = function(){}; 

你必須聲明你調用前變量函數:

//Ok 
var getValue = function(){}; 
getValue(); 

你也可以寫類似

//Ok because code block is parsed before runtime 
getValue(); 
function getValue(){}; 

所以在這裏你plunker編輯 https://plnkr.co/edit/YqeyaLqW2B6xn4VHcVlQ?p=preview

+0

:這就是爲什麼我發佈這個:/我找不到錯誤。 –

+0

您的錯誤不是由您提供的部分代碼引起的。你能用你的控制器/視圖創建一個plunker/jsfiddle嗎? –

+0

https://plnkr.co/edit/uq5xbJubgTmZQ2cUqVvs?p=preview –

5

我知道的答案已經被接受,但讓我想提供一個備用建議它並沒有解決我的問題。

我遇到了完全相同的情況,結果證明我使用的是尚未引入.prompt()的舊版Angular Material。如果您查看docs for the version I was using(1.0.5),您會在演示中看到對話框沒有提示選項。但是,如果您查看docs for the latest version(截至撰寫本文時爲1.1.0),提示選項就在那裏。

希望這有助於任何遇到此問題的人像我一樣。