Catfish
Catfish

Reputation: 19324

Setting scope variable in controller is undefined

If i set a scope variable like this it works just fine:

$scope.event = new Date();

but if i set this, i get an undefined error:

$scope.event.start.time = new Date();

Why and how can I set $scope.event.start.time?

Upvotes: 0

Views: 412

Answers (1)

raina77ow
raina77ow

Reputation: 106483

With something like this:

$scope.event = {
  start: {
    time: new Date()
  }
};

Otherwise, as JS doesn't have auto-vivification, you'll attempt to access (set) a property of undefined.

Upvotes: 3

Related Questions