雖然答案可能在於Angular,但我正在開發一個簡單的離子移動應用程序。該應用程序非常簡單,通過顯示模式的添加按鈕顯示員工列表,讓用戶輸入一些詳細信息,點擊保存並將數據保留到後端Firebase商店。它有1個控制器和一個簡單的服務。最初,我有index.html裏面的modal內部腳本標籤的模板html,它一切正常。當我決定將結構模板放在一個單獨的html文件中時,突然間通過輸入框分配給ng-modal的數據對象不再將任何數據傳遞給事件處理程序來保存數據,而是始終未定義數據對象。其他一切正常,模態顯示正常,事件處理程序正在調用正確的功能等。唯一的變化是將輸入模板移動到單獨的文件中。我知道這可能是一件非常簡單的事情,但不能爲我的生活找出原因並找不到任何其他地方的任何信息。使用單獨的模板html文件傳遞來自離子/角模態的數據
的模式模板HTML文件:
<ion-list>
<h1>Add Employee</h1>
<div class="list list-inset">
<ion-item>
<label class="item item-input">
<input type="text" placeholder="Employee Name" ng-model="data.employeeName">
</label>
<label class="item item-input">
<input type="text" placeholder="Employee Age" ng-model="data.employeeAge">
</label>
</ion-item>
<button class="button button-outline button-block button-balanced"
ng-click="addEmployee(true, data)">
Save & Add Another
</button>
<button class="button button-outline button-block button-positive"
ng-click="addEmployee(false, data)">
Save
</button>
<button class="button button-outline button-block button-assertive"
ng-click="closeAddModal()">
Cancel
</button>
</ion-list>
</ion-modal-view>
addEmployee事件 - 數據參數現在始終不確定。嵌入式模板工作得很好:
$scope.addEmployee = function(retainModal, data) {
var employee = {employeeName:data.employeeName,
employeeAge:data.employeeAge};
employeeService.saveEmployee(employee);
if (! retainModal) {
$scope.closeAddModal();
};
data.employeeName = "";
data.employeeAge = "";
};
Wheres employeeService?你是否承諾承諾? – Fals 2014-12-05 12:44:28
不答覆。 addEmployee函數沒有達到調用employeeService.saveEmployee的程度,因爲它在嘗試組裝employee對象時出錯,因爲從模板傳回的數據參數未定義。當模式模板HTML在index.html中時,這工作得很好,但只要我將它移到它自己的文件中,我就會遇到這個問題。 – 2014-12-05 14:26:08