Search code examples
angularjsangularjs-directiveangularjs-scope

How to get Data from AngularJS using a scope with different kinds of Properties?


I have assigned to an scope object an object (class) but this class has two attributes: two arrays and two strings, how can I get the values from this $scope?

Ex: Object to Assign:

    var Address = new List<string> { "460 jones", "560 Ultimo" };
    var Telefonos = new List<string> { "0450003514", "046007989" };
     var SettingsDetails = new SettingsDetails
       {
           Name = "Diego ",
           Email= "[email protected]",
           Direcciones = Address,
           Telefonos=Telefonos

       };

in the view:..

.............

          angular.copy(result.data, $scope.data)   

..............

I have a copy of SettingsDetails in $scope.data but how can I get the values of the array? easily I can get the string of this way {{ data.name }} but the array in the same view?


Solution

  • You can get "460 jones" using {{ data.Direcciones[0] }}

    For a better way, you can use ngRepeat directive. See this link.

    for example:

    Addresses:
    <ul>
       <li ng-repeat="address in data.Direcciones" >{{ address }}</li>
    </ul>
    Telefonos:
    <ul>
       <li ng-repeat="telefono in data.Telefonos" >{{ telefono }}</li>
    </ul>