0

I have an object I want to use as a model for my angular controller.

var SchedulingModel = function() {
    this.weekdays = Weekdays;
    this.scheduleType = "2";
    this.customerType = "1";
    this.timesOfTheMonth = TimesOfTheMonth;
    this.waivers = [];
}

angular controller:

$scope.model = SchedulingModel;

When I try and access model.weekdays and model.timesOfTheMonth they are both undefined...

console.log($scope.model.timesOfTheMonth);
console.log($scope.model.weekdays);

Why is this?

2 Answers 2

2

you need to do new of SchedulingModel

$scope.model = new SchedulingModel();
Sign up to request clarification or add additional context in comments.

1 Comment

As a new JS developer, I thought it was unusual that I was able to assign the objects without instantiating instances of them
1

In that case it is not angular thing. Please try:

console.log(SchedulingModel.weekdays) //undefined
// but this will work
var TimesOfTheMonth = '';
var Weekdays = "";
var a = new SchedulingModel();
console.log(a.weekdays); //works ok

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.