A
A
Alex2015-03-03 07:18:41
Angular
Alex, 2015-03-03 07:18:41

Refactoring angularjs code?

Hello!
I study angulars and js in general, the question has ripened.
It is possible to optimize the code somehow. Let's say write a function that substitutes id or something like that.
And then there can be a hundred of such fields, and I don’t want to write all this with a bydlocode.

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)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Philipp, 2015-03-03
@zoonman

stackoverflow.com/questions/15666048/service-vs-pr...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question