I am having trouble loading a second controller to populate a select in my view. Despite my efforts, it just won't cooperate. This is the code snippet I'm using:
app.js
(function() {
'use strict';
angular
.module('app.lazyload')
.constant('APP_REQUIRES', {
scripts: {
'modernizr': ['vendor/modernizr/modernizr.custom.js'],
'icons': ['vendor/fontawesome/css/font-awesome.min.css',
'vendor/simple-line-icons/css/simple-line-icons.css'],
'companiesCtrl': ['app/js/modules/companies/data.js','app/js/modules/companies/controller.js'],
'companyDetailCtrl': ['app/js/modules/companies/data.js','app/js/modules/companies/controller_detail.js'],
'documentTypeCtrl': ['app/js/modules/document_type/data.js','app/js/modules/document_type/controller.js']
});
})();
////////////////////////////////////
.state('app.companies.detail', {
url :'/companies.detail/',
title : 'Company',
templateUrl : helper.basepath('companies/companies.detail.html'),
resolve : helper.resolveFor('companyDetailCtrl','documentTypeCtrl'),
controller : ('companyDetailCtrl')
})
.state('app.companies.document_type', {
url :'/companies.detail/',
title : 'Document Type',
templateUrl : helper.basepath('companies/companies.detail.html'),
controller : ('documentTypeCtrl')
})
company.detail/controller.js
(function() {
'use strict';
angular
.module('assets4')
.controller('companyDetailCtrl', companyDetailCtrl);
companyDetailCtrl.$inject = ['$scope','Data','$log', '$state'];
function companyDetailCtrl($scope, Data, $log, $state){
$log.log('Controller > companyDetailCtrl loaded');
Data.get('companies/'+$scope.company_id).then(function(data){
$scope.companyDetail = data[0];
});
};
})();
document_type/controller.js (this file is loaded correctly in browser)
(function() {
'use strict';
angular
.module('assets4')
.controller('documentTypeCtrl',documentTypeCtrl)
documentTypeCtrl.$inject = ['$scope','DataDocType','$log'];
function documentTypeCtrl($scope, DataDocType, $log, $state) {
DataDocType.get('document_type').then(function(data){
$scope.document_type = data;
$log.log('Controller > documentTypeCtrl loaded');
});
};
})();
EDIT > added companies/controller.js
(function() {
'use strict';
angular
.module('assets4')
.controller('companiesCtrl', companiesCtrl)
companiesCtrl.$inject = ['$scope','Data','$log', '$state'];
function companiesCtrl($scope, Data, $log, $state) {
Data.get('companies').then(function(data){
$scope.companies = data;
$log.log('Controller > companiesCtrl loaded');
});
$scope.onRowClick = function(company_id){
$scope.company_id = company_id;
$state.go('app.companies.detail');
};
};
})();
EDIT > added companies.html
<div class="row" ng-controller="PanelsCtrl as panel">
<div class="col-xs-12">
<div class="panel panel-default" >
<div class="panel-heading">
<paneltool tool-refresh="traditional"></paneltool>
</div>
<div class="panel-body">
<div ui-view>
<div class="table-responsive">
<table id="companiesGrid" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>ID</th>
<th>{{ 'companies.grid.NAME' | translate }}</th>
<th>{{ 'companies.grid.DOCUMENT' | translate }}</th>
<th>{{ 'companies.grid.ADDRESS' | translate }}</th>
<th>{{ 'companies.grid.PHONE1' | translate }}</th>
<th>{{ 'companies.grid.EMAIL' | translate }}</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="company in companies track by $index" ng-class="{'active': company.company_id}" ng-click="onRowClick(company.company_id)">
<td>{{company.company_id}}</td>
<td>{{company.company_name}}</td>
<td>{{company.company_document_number}}</td>
<td>{{company.company_address}}</td>
<td>{{company.company_phone1}}</td>
<td>{{company.company_email}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
EDIT > added companies.detail.html
<form role="form" class="form-horizontal"gt;
<div class="form-group">
<label class="col-lg-2 control-label">{{'companies.grid.ID' | translate}}</label>
<div class="col-lg-10">
<input type="text" placeholder="" class="form-control" ng-model="companyDetail.company_id" disabled/>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">{{'companies.grid.NAME' | translate}}</label>
<div class="col-lg-10">
<input type="text" placeholder="" class="form-control" ng-model="companyDetail.company_name"/>
</div>
</div>
<div class="form-group mb">
<label class="col-lg-2 control-label">Chosen Ajax</label>
<div class="col-lg-10">
<select chosen="" ng-model="document_type" ng-options="s for s in form.states" width="'100%'" class="chosen-select input-md">
<option value=""></option>
</select>
</div>
</div>
... <!-- Additional form fields-->
</form>
app.company.detail is functioning perfectly and populating the entire form.
I have also tried using `ng-controller` but unfortunately, nothing seems to work.
I am unable to access this specific code
$log.log('Controller > documentTypeCtrl loaded');
Could someone please point out what I might be doing wrong? As a newcomer to Angularjs, any guidance would be greatly appreciated.
Thank you.