So I am using require.js and knockout.js together. I have a simple page that will the collect users.
Here is the code:
cshtml file:
@section scripts{
<script data-main="../Scripts/app/usermanagement/app.invite" src="../Scripts/lib/require.js"></script>
}
<div id="usermanagement-invite-view">
<p>Enter all the users you would like to invite to this account. You will be able to set the permissions onces you have added them.</p>
<span data-bind="text: ko.toJSON($data)"></span>
<div data-bind="foreach: invitedUsers()">
<div><span data-bind="text: firstName"></span></div>
<div><span data-bind="text: lastName"></span></div>
<div><span data-bind="text: emailAddress"></span></div>
</div>
<div>
<input type="text" placeholder="First Name" data-bind="text: firstName" class="input" />
<input type="text" placeholder="Last Name" data-bind="text: lastName" class="input" />
<input type="email" placeholder="EmailAddress" data-bind="text: emailAddress" class="input" />
<input type="button" value="Invite" data-bind="click: invite" class="submit" />
</div>
</div>
Here is the app.invite.js
requirejs.config({
"baseUrl": "../Scripts/app/usermanagement",
"paths": {
"app.invite": "app.invite",
"ko": "../../lib/knockout-2.2.1",
"jquery": "//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min",
"toastr": "../../lib/toastr"
}
});
// Load the main app module to start the app
require(["main.invite"], function (bs) { bs.run(); });
Here is the main.invite.js:
define(['ko', 'inviteViewModel'], function (ko, inviteViewModel) {
var
run = function () {
var vm = new inviteViewModel();
ko.applyBindings(vm, document.getElementById('#usermanagement-invite-view'));
};
return {
run: run
};
});
Here is the inviteViewModel:
define('inviteViewModel', ['jquery', 'ko', 'toastr', 'model.user'], function ($, ko, toastr, User) {
return function inviteViewModel() {
var self = this;
self.firstName = ko.observable();
self.lastName = ko.observable();
self.emailAddress = ko.observable();
self.invitedUsers = ko.observableArray();
self.invite = function () {
var newUser = new User();
newUser.firstName(self.firstName());
newUser.lastName(self.lastName());
newUser.emailAddress(self.emailAddress());
self.invitedUsers().push(newUser);
console.log(self.invitedUsers());
};
}
});
For some reason, when i call the invite function, the code shows that I am adding something to collection, but the UI doesn't get updated. Here what it looks like when i do a console.log. This however doesn't show the value being

What am I doing wrong?