distributed icon indicating copy to clipboard operation
distributed copied to clipboard

$scope is used too much in mainController

Open Roshanjossey opened this issue 7 years ago • 5 comments

Currently mainController.js is a big file with lot of business logic and functionality defined in $scope.

From what I learned so far it's better to use controllerAs syntax and reduce the use of $scope. Also business logic should reside in controller.

I think this is a good time to refactor mainController.js to make the codebase better

Roshanjossey avatar Jan 31 '17 21:01 Roshanjossey

Do you mean something like this?

`<div ng-controller="MainCtrl as main">
      {{ main.title }}
 </div>`

And also, I would suggest using 'this' instead of binding everything to scope all the time. app.controller('MainCtrl', function () { this.title = 'Some title'; });

What do you guys think? @Roshanjossey , @glauberramos

alanjsph avatar Apr 02 '17 17:04 alanjsph

@alanjsph, Yes. Did you get it from here ?

I was thinking about extracting directives and controllers out to different files.

Just keeping view in directives and put business logic in controllers.

Roshanjossey avatar Apr 02 '17 19:04 Roshanjossey

@Roshanjossey , No I didnt get it from there. But aren't the directives already in different files? Correct me if I'm wrong.

alanjsph avatar Apr 02 '17 20:04 alanjsph

Yes directives are in multiple files. It'd be good to split controllers too.

I don't really know how it should end up. There are functions to be used by different directives.

Roshanjossey avatar Apr 02 '17 20:04 Roshanjossey

ok, @Roshanjossey Let me have a try

alanjsph avatar Apr 02 '17 20:04 alanjsph