Ionic - Uncaught SyntaxError:意外的令牌

时间:2016-07-24 19:30:39

标签: javascript android angularjs ionic-framework firebase

我使用的Ionic Framework版本是1.7.16

在Android上导致错误的行是

var obj = {[$myid] : firebase.database.ServerValue.TIMESTAMP};

如果我将上面的行更改为以下行,则没有错误

var obj = {'test':'test'};

Ctrl Code:

.controller('SearchStateCtrl', function($scope, $firebaseObject, $firebaseArray, $location, $stateParams, my_details) {
  $scope.stateId = $stateParams.stateId;
  $scope.my_details = my_details;

  var user = firebase.auth().currentUser;
  $scope.my_id = user.uid;

  var database = firebase.database();
  var trips = database.ref('Trips/'+$stateParams.stateId);

  trips.on('value', function(snapshot) {
    $scope.my_trips = $firebaseArray(trips);
  }, function(err) {
     console.log("Something is wrong.");
  });

  $scope.addToMyTrip = function ($trip, $myid) {
    var tripRef = database.ref('MyTrips');
    var obj = {[$myid] : firebase.database.ServerValue.TIMESTAMP};
    tripRef.set(obj).catch(function(error) {
      console.log('Somthing went wrong.');
    });
    var tripRef = database.ref('MyTrips/'+$trip.$id);
    tripRef.set({
      'i-am': $trip['i-am'],
      'trip-date': $trip['trip-date'],
      'state-from': $trip['state-from'],
      'city-from': $trip['city-from'],
      'state-to': $trip['state-to'],
      'city-to': $trip['city-to'],
      'user-id': $trip['user-id']
    }).catch(function(error) {
      console.log('Somthing went wrong.');
    });
  }
})

动态键名由于某种原因在android上出错,当我在网页中使用

查看时,一切正常
ionic serve --lab

Error i am getting when i am deploying on android

1 个答案:

答案 0 :(得分:0)

感谢Emmanuel Delay,通过更改以下行来解决问题

var obj = {[$myid] : firebase.database.ServerValue.TIMESTAMP};

var key = [$myid]; 
var obj = {}; 
obj[key] = firebase.database.ServerValue.TIMESTAMP;