What’s the correct way to communicate between controllers in AngularJS?

What’s the correct way to communicate between controllers? I’m currently using a horrible fudge involving window: function StockSubgroupCtrl($scope, $http) { $scope.subgroups = []; $scope.handleSubgroupsLoaded = function(data, status) { $scope.subgroups = data; } $scope.fetch = function(prod_grp) { $http.get(‘/api/stock/groups/’ + prod_grp + ‘/subgroups/’).success($scope.handleSubgroupsLoaded); } window.fetchStockSubgroups = $scope.fetch; } function StockGroupCtrl($scope, $http) { … $scope.select = function(prod_grp) { … Read more

Why Is `Export Default Const` invalid?

I see that the following is fine: const Tab = connect( mapState, mapDispatch )( Tabs ); export default Tab; However, this is incorrect: export default const Tab = connect( mapState, mapDispatch )( Tabs ); Yet this is fine: export default Tab = connect( mapState, mapDispatch )( Tabs ); Can this be explained please why const … Read more

What is the purpose of wrapping whole Javascript files in anonymous functions like “(function(){ … })()”?

I have been reading a lot of Javascript lately and I have been noticing that the whole file is wrapped like the following in the .js files to be imported. (function() { … code … })(); What is the reason for doing this rather than a simple set of constructor functions? 9 s 9

How do I access previous promise results in a .then() chain?

I have restructured my code to promises, and built a wonderful long flat promise chain, consisting of multiple .then() callbacks. In the end I want to return some composite value, and need to access multiple intermediate promise results. However the resolution values from the middle of the sequence are not in scope in the last … Read more

Is there a reason for C#’s reuse of the variable in a foreach?

When using lambda expressions or anonymous methods in C#, we have to be wary of the access to modified closure pitfall. For example: foreach (var s in strings) { query = query.Where(i => i.Prop == s); // access to modified closure … } Due to the modified closure, the above code will cause all of … Read more