I have created an application with angularjs having the ng-view feature. The application works fine but the problem is for all the view the .run within the employee module is getting executed.Since within that .run i have a service call, so when i switch to either department, employee or humanresource view the .run is getting executed which is supposed i need to get executed when employee view is triggered.
can anyone please tell me some solution for this
angular.module('main', ['employee', 'department', 'humanresource', 'ngRoute'])
.config(
function($routeProvider)
{
$routeProvider.when('/humanresource',
{
templateUrl: 'humanresource/resource.html',
controller: 'EmployeeCtrl'
}).when('/employee',
{
templateUrl: 'employee/employee.html',
controller: 'HumanResourceCtrl'
}).when('/department',
{
templateUrl: 'department/department.html',
controller: 'DepartmentCtrl'
}).otherwise(
{
redirectTo: '/employee'
});
}
);
employee.js
angular.module('employee', [ 'common' ] )
.run(function($rootScope, EmployeeDetails)
{
$rootScope.employeeDetails = EmployeeDetails.get(function(data)
{
$rootScope.employeeDetails = _.clone(data.properties, true);
});
})
.controller('EmployeeCtrl', function($rootScope, $scope)
{
:
:
}
);
department.js
angular.module('department', [ 'common' ] )
.controller('DepartmentCtrl', function($rootScope, $scope)
{
:
:
}
);
humanresource.js
angular.module('humanresource', [ 'common' ] )
.controller('HumanResourceCtrl', function($rootScope, $scope)
{
:
:
}
);
employee.html
<div>
<form ng-submit"submitEmployee()">
<div ng-controller="EmployeeCtrl">
:
:// content for the emnployee adding and display
:
:
</div>
</form>
</div>
department.html
<div>
<form ng-submit"submitDepartment()">
<div ng-controller="DepartmentCtrl">
:
:
:// content for the department adding and display
:
</div>
</form>
</div>