我正在使用此Popup Dialog service,因为它似乎是受欢迎的对话框。我按如下方式调用弹出对话框:
$scope.upload = function() {
createDialogService('simpleModal.html', {
id: 'simpleDialog',
title: 'Upload Video to save India',
backdrop: true,
controller: 'TrafficListController',
success: {label: 'Success', fn: function() {console.log('Simple modal closed');}}
});
};
我的simpleModal.html仅包含以下内容(表单)
<div class="row-fluid">
<form ng-submit="addNewVideo()">
<input type="text" ng-model="newVid.videoURL" placeholder="Video URL here"> <br/>
<input type="text" ng-model="newVid.locality" placeholder="locality"> <br/>
<input type="text" ng-model="newVid.town" placeholder="town"> <br/>
<input type="text" ng-model="newVid.city" placeholder="city"> <br/>
<input type="text" ng-model="newVid.pincode" placeholder="Pin Code" value="600015"> <br/>
<input type="text" ng-model="newVid.time" placeholder="yyyy-mm-dd hh:mm" value="2014-03-20 08:20"> <br/>
<input type="SUBMIT" value="Add Video" class="btn-primary">
</form>
</div>
但是当我点击弹出窗体中的“提交”按钮时,它会抛出错误TypeError: Cannot read property 'videoURL' of undefined
而我的addNewVideo()
看起来像这样:
$scope.addNewVideo = function() {
var vid = {};
$log.log($scope);
vid["videoURL"] = $scope.newVid.videoURL;
vid["thumbURL"] = $scope.newVid.videoURL;
vid["uploadedBy"] = "someone";
vid["analyzedBy"] = "";
vid["locality"] = $scope.newVid.locality;
vid["town"] = $scope.newVid.town;
vid["city"] = $scope.newVid.city;
vid["pincode"] = $scope.newVid.pincode;
vid["time"] = $scope.newVid.time;
var json = JSON.stringify(vid);
}
但是如果我将表单嵌入页面本身而不是弹出窗口,它就可以了。我不确定弹出窗口是否使用TrafficListController
的相同实例或创建新实例。即使它创建了一个新实例,该特定函数addNewVideo()
也不依赖于另一个实例的任何其他属性/变量而应该起作用。
我错了什么?有什么帮助吗?
参考文献: index.html:https://github.com/GethuGames/Traffic-Violations-Portal/blob/master/index.html trafficListController.js:https://github.com/GethuGames/Traffic-Violations-Portal/blob/master/trafficListController.js
答案 0 :(得分:2)
您正尝试在addVideo函数上阅读$scope.newVid
,但它不存在。尝试首先初始化此对象。