I am having an issue where my controller variables are not being initialized correctly as per the controller code.
The controller code is
angular.module('test')
.controller('RegisterCtrl', function RegisterCtrl($scope) {
var vm = this;
vm.model = {companyName:'aaa'};
vm.data= [{fieldtype: 'input',key:'companyName'}];
});
The ui-router is
.state('register', {
// abstract: true,
url: "/register",
templateUrl: "/views/register.html",
controller: 'RegisterCtrl',
controlleras: 'vm'
})
I have a verify basic html to show the output of model:
<h2>Model</h2>
<pre>{{vm.model }}</pre>
When debugging the code in chrome it passes through the controller code and sets both model and data correctly, but when the page has finished loading the vm.model is blank.I am not sure what I am doing incorrectly.
Thanks in advance.
ui-router
does not have acontrolleras
property. You need to specify it in yourcontroller
property instead (i.e.controller: 'RegisterCtrl as vm'
).controllerAs
. This is a simple typo.