A
A
Anton2016-06-27 14:24:46
Angular
Anton, 2016-06-27 14:24:46

Why is $scope bad?

I have heard more than once that they say that using scope is bad, tell me why this is so?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey, 2016-06-27
@MAKAPOH

In my practice, I came across some inconveniences related to the fact that child scopes prototypically inherit parent ones, while it turns out that all the variables declared above are present in the nested scope itself. If you have the same variable names there, then it is easy to catch an error by changing the wrong variable. Starting to work with ui-router with a bunch of nested states, I immediately ran into this due to inexperience. With the ControllerAs syntax, as I understand it, your data is in the controller and not in the scope and such errors do not occur.
ps I'm not a pro at angular, just thinking out loud :)

N
Nicholas, 2016-06-27
@healqq

$scope is not bad, it's an outdated approach. Now (angular 1.5+) an application is a collection of components. Each component has its own controller, which allows you to hang all the bindings.
$scope gives too much liberties: for example, you can fly into the parent $scope and change something there. It is very easy. And how hard it will be after a while to maintain this mess.

M
Maxim Kuznetsov, 2016-06-27
@NewProject1

Maybe it was about $rootScope? If so, then using $rootScope is about the same as using global variables.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question