2016-05-13 110 views
0

AngularJS的特性 'myInputName' 是給我下面的錯誤:AngularJS:無法讀取未定義

AngularJS error

其中titleInput是我的文本框的name屬性:

@Html.TextBox("titleInput", null, new { @placeholder = @T("Message title"), @class = "form-control", ng_model = "feed.feedData().title", ng_required = "true" }) 

FeedValidationService方法,讓我那個錯誤是:

public titleInputValidation(messageForm: any, isTitleInputValid: boolean): boolean { 
    if (messageForm.titleInput.$valid) { 
     isTitleInputValid = true; 
    } 
    else { 
     isTitleInputValid = false; 
    } 

    return isTitleInputValid; 
} 

這是工作,一切都可以,除了瀏覽器中的這個錯誤。我怎樣才能擺脫這一點?

回答

1

我建議你檢查是否設置了messageForm
我的意思是:if (messageForm && messageForm .titleInput.$valid)

if (messageForm != undefined) { /*do your logic here */ }

+1

是啊! :)我忘了檢查messageForm是否存在。謝謝 :) – Marox

相關問題