Refactoring angularjs code?

Hello!

Study angulars and js in General, there is a question.
It is possible to optimize the code. Say to write a function that substitutes id or something like that.
And that such fields may be hundreds, and write it all bydlokod not want to.

app.controller "addCitysPage", ($rootScope, $scope, $timeout, getDataService, setPlace ) ->

 $scope.show3 = () ->
 $scope.city3 = $rootScope.citys
 $scope.show4 = () ->
 $scope.city4 = $rootScope.citys
 $scope.show5 = () ->
 $scope.city5 = $rootScope.citys
 $scope.show6 = () ->
 $scope.city6 = $rootScope.citys

 objectResult = (e) ->
 { "id" : e.target.dataset.id, "name" : e.target.dataset.name, "cdr" : e.target.dataset.cdr }

 $scope.selectionCity3 = (e) ->
 $scope.search3City = setPlace.setCity(e.target.dataset, 3)
 $rootScope.Items.Citys.city3 = objectResult(e)
 $scope.selectionCity4 = (e) ->
 $scope.search4City = setPlace.setCity(e.target.dataset 4)
 $rootScope.Items.Citys.city4 = objectResult(e)
 $scope.selectionCity5 = (e) ->
 $scope.search5City = setPlace.setCity(e.target.dataset 5)
 $rootScope.Items.Citys.city5 = objectResult(e)
 $scope.selectionCity6 = (e) ->
 $scope.search6City = setPlace.setCity(e.target.dataset 6)
 $rootScope.Items.Citys.city6 = objectResult(e)
September 19th 19 at 00:05
1 answer
September 19th 19 at 00:07
Do not quite understand, and then factories, etc.
I think we should add some kind of service, it's obvious.
If the analogy with PHP, it would be something like this:
// js $scope.city6 = $rootScope.citys
$this->scope->$show_number = $this->rootScope->citys
- lamar commented on September 19th 19 at 00:10
: this is an example of bad code. So you can not write, this is anti-pattern.
You need to add an extra dimension. This is how to move from a one-dimensional array two-dimensional. - rylan96 commented on September 19th 19 at 00:13
: All symfony so implemented in bootstrap
public function __construct(array $parameters = array())
{
 $this->parameters = $parameters;
}


Why is this suddenly became a bad code? - minerva.Kassul commented on September 19th 19 at 00:16
public function replace($parameters)
{
 return $this->$parameters[$root]
}
- minerva.Kassul commented on September 19th 19 at 00:19
: because Simfony is not a bad code and framework built for people with an understanding of the application design. Before writing on this level, you need to understand what you're doing, and not just drag code. But understanding comes after the realization of the necessity of application testing, the appropriateness of approaches in a particular situation. You can take for example, Bitrix, it is possible to find as reasonable, and frankly govnokod solutions. - rylan96 commented on September 19th 19 at 00:22

Find more questions by tags AngularCoffeeScript