【发布时间】:2014-11-09 05:40:37
【问题描述】:
我想在提交输入时保存地理坐标以进行内部数据排序。
它显示坐标,即加载当前位置。但是,数据并未保存,而是不断刷新。我尝试将其另存为:
位置:{lat:'',lng:''}
如何确保保存数据而不仅仅是刷新当前位置?
导航栏控制器
app.controller('NavCtrl', function($scope, $location, Post, Auth, $state, Geolocation) {
$scope.post = {
title: '',
lat: '',
lng: ''
};
同一控制器下提交函数
$scope.submitPost = function () {
Post.create($scope.post).then(function (ref) {
$location.path('tab/posts/' + ref.name());
$scope.post = {
title: '',
lat: '',
lng: ''
};
$scope.position = null;
$scope.message = 'Determining location...';
new Geolocation().then(function (position) {
$scope.position = position;
}, function (reason) {
$scope.message = 'Could not be determined';
});
也在主控制器下
app.controller('MainCtrl', function($scope, Post) {
$scope.posts = Post.all;
$scope.post = {
title: '',
lat: '', //inserted geodata to be reflected in main page
lng: ''
};
【问题讨论】:
-
我在您包含的代码中看不到任何 Firebase 的使用。鉴于您正在使用的技术数量,如果您在 fiddle/bin/plunkr 中设置问题的重现可能会更好。
-
@FrankvanPuffelen 感谢您的回复!很快就会设置并在这里发布。对此感到抱歉。
-
如果无法重现问题,或许可以尝试简化plunkr,直到可以重现问题?鉴于您的问题的标题,必须有一种方法可以用更少的文件和技术来重现它。 stackoverflow.com/help/mcve
-
看我的回答。如果您编写一个涉及较少技术的正确问题,您可能会得到更好的答案。诸如“为什么我的控制器被多次调用?”之类的东西应该能够在不使用 Firebase 和 Ionic 的情况下重现该行为。通过减少使用的技术数量,您可以扩大可以回答您问题的受众。
标签: javascript html angularjs geolocation firebase