0

I have an json array of

[{
"id": "21390238becde1290",
"chelsea": {
    "homeTeam": "chelsea",
    "sortName": "ches",
    "awayTeam": "Maribor",
    "awayShort": ""
},
"barclays": {
    "id": "21390238becde1290",
    "homeTeam": "barclays",
    "sortName": "barc",
    "awayTeam": "Hull",
    "awayShort": ""
}
}]

Controller:

footBallApp.controller('TeamInfoEdit',
    function ($rootScope, $scope, $state, $translate, carwashService) {

        $rootScope.washTypes;

        $scope.onViewLoaded = function () {
           matchService.getTeamTypes($scope.TypeSelected);
        }

        $scope.TypeSelected = function (response) {
            debugger;
            if (response) {
                $rootScope.teamAvailable = response;
                $scope.localizedTeamName = getLocalizedCollection($scope.teamAvailable);
            }
        }

        // Editing the Team Details.

        $scope.editTeamDetails = function (key) {
            console.log(key._id);

            $rootScope.selectTeam =[]; 
            for(var i=0; i<$scope.teamAvailable.length;i++){
            if($scope.teamAvailable[i]._id== key._id)
            {
                console.log($scope.teamAvailable[i]);
                $scope.selectTeam.push($scope.teamAvailable[i]);
                debugger;

And I have assigned the array to $scope.selectTeam. When Im trying to call $scope.selectTeam.chelsea.Im getting it as Undefined in the console. While calling the json I'm going wrong but couldn't find it, so how do I call the array correctly. So looking for help in this.

4
  • 1
    Can you show the code that is used to assign the object (not an array) to the $scope? And also the place you're attempting to read it again. Commented Dec 13, 2016 at 12:00
  • 1
    its all working here - jsfiddle.net/Lvc0u55v/13212 Commented Dec 13, 2016 at 12:01
  • 1
    If above is your JSON object, the it is incorrect. For more help, please share the code. Commented Dec 13, 2016 at 12:01
  • need full code, usage depends on where you use it Commented Dec 13, 2016 at 12:01

2 Answers 2

2

I don't know how your array looks like, but try to call:

$scope.selectTeam[0].chelsea
Sign up to request clarification or add additional context in comments.

Comments

0

Array is coming because of uninitialized. If you initialize $rootScope.teamAvailable = {}; then if response data comes in json format it will overwrite.

1 Comment

I'm still getting undefined

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.