0

I have an object Array 'Vacations'

$scope.Vacations = [{Id:'1' ,VacationType = {TypeId='1' ,TypeName = 'test'}}];

it contain other object Array 'VacationType' with one set only

I want to extract TypeId

I Did somthing like this :

$scope.selectedVacationType = [];
$scope.TypeTd;

$scope.selectedVacationType=Vacations.VacationType;
$scope.TypeTd;= $scope.selectedVacationType[0].Id;

But this is not working

What can be done ?

1 Answer 1

1

Use $scope.selectedVacationType=Vacations[0].VacationType;

The Vacations represents list of items [...]

BTW, your model is wrong, remove = and replace with :

 $scope.Vacations = [{
        Id: '1',
        VacationType : {
           TypeId : '1',
           TypeName : 'test'
        }
    }];

HTML

selectedVacationType: <pre>{{selectedVacationType|json}}</pre>
TypeTd:               <pre>{{TypeTd|json}}</pre>
TypeName:             <pre>{{TypeName|json}}</pre>

controller

    $scope.Vacations = [{
    Id: '1',
    VacationType : {
    TypeId : '1',
        TypeName : 'test'
    }
}];

$scope.selectedVacationType = $scope.Vacations[0].VacationType;
$scope.TypeTd = $scope.selectedVacationType.TypeId;
$scope.TypeName = $scope.selectedVacationType.TypeName;

Demo Fiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.