Struggling to correctly access controller object properties in my view while using ui-router for routing with nested scopes. Want to implement 'controller as' syntax but facing syntax issues.
app.js (routing setup)
(function() {
angular
.module('ICP_App', ['ui.router', 'satellizer', 'ngMaterial', 'ngMessages', 'xeditable'])
.config(function($stateProvider, $urlRouterProvider, $authProvider) {
$urlRouterProvider.otherwise('dashboard');
$stateProvider
.state('clients', {
url: '/clients',
templateUrl: '../partials/clients-index.html',
controller: 'ClientsController as ClientsCtrl'
})
// more routes here...
})();
ClientsController.js
(function() {
angular.module('ICP_App')
.controller('ClientsController', function($http) {
$http.get('http://api.icp.sic.com/clients')
.success(function(clients) {
var vm = this;
vm.clients = clients.data;
console.log(vm.clients);
})
.error(function(error) {
// handle here
})
});
})();
index.html
<body ng-app="ICP_App" ng-cloak>
<!-- sidebar, header etc -->
<div ui-view></div> <!-- pull in view -->
</body>
Finally, clients-index.html
partial
<div class="content">
<div class="pane" ng-repeat="client in clients">
{{ client.name }}
</div>
</div>
Attempted using client in vm.clients
without success.
Is there an issue with my 'controller as' syntax? Using it in ui-router but encountering errors when setting up the controller. Using 'controller as' again in the controller results in an error (
Argument ClientsController is not a
).
While console logging vm.clients displays the data, unable to access it in the view.
Thank you for any assistance.