I have read in the ngInit docs that says:
The only appropriate use of ngInit for aliasing special properties of ngRepeat, as seen in the demo below. Besides this case, you should use controllers rather than ngInit to initialize values on a scope.
We have developed one Enterprise application, the complete client side framework is built on AngularJS and the server framework is on ASP.NET Web API. In the application we have 350+ html pages and 250+ Web APIs. There are lots of areas where we initialize the data from ng-init directive via controller function. Because in our application all data is coming from the ASP.NET Web APIs. Please check below code example :
HTML template code to initialize the industry data and bind into the grid:
<div ng-init="initIndustries()">....</div>
Industry Controller
app.controller("industryCtrl",["$scope",function($scope){
//Sets the server data in the $scope property.
$scope.initIndustries = function(){
//perform ajax request and set the data into the $scope property.
}
$scope.initAddIndustry = function(){
// perform ajax request for getting a dropdown data on Add Industry Page.
}
}])
1. Are we doing something wrong to initialize the data via function because all data is coming from the Server APIs?
2. Current initialization approach is against the standard practices in AngularJS based application. if yes, then which approach we need to follow in the application?
the reason to implement the above approach, Due to large application my initial thought was to follow MVC philosophy of decoupling the code and separation of concerns.
If we follow the Angularjs ngInit Doc Example, as per my assumption we need to create four controller for performing CRUD operation on single entity(Industry). say for example I want to load the industry data on the page and also perform Create, Update and Delete operation on a different HTML templates. as per the above scenario, Do I need to create four controller to achieve this functionality or Is there any other way of doing?