0

Please refer to this plunkr, plunkr WHat I want is

If I click of Reading Korean then it should display its nested part i.e. Vowels,Consonants,Simple Words,Harder Words

angular.module('Tutorials', []).controller('getAnswers', function ($scope, $element) {
    $scope.sectionNumber = 0;
    $scope.tutorialNumber = 0;
  $scope.questionNumber = 0;
	$scope.sections = sections;
	$scope.loadFromMenu = function (tut) {
      alert(tut);
			if (tut === $scope.tutorialNumber && tut !== 0) {
				return;
			} //if clicked on already playing tut
			if (tut !== undefined) {
				$scope.tutorialNumber = tut;
			}
			var section = sections[$scope.sectionNumber];
			for (var i in section.tutorials) {
				section.tutorials[i].active = "inactive";
			}
			section.active = "active";
			section.tutorials[$scope.tutorialNumber].active = "active";
			$scope.$apply();
			$scope.questionNumber = 0;
			if ($scope.sectionNumber === 1){
				conjugationController();
			}
		};

});

var sections = [{
    active: "inactive",
    name: "Reading Korean",
  romanizeService: "http://www.kawa.net/works/ajax/romanize/romanize.cgi?q=%ED%96%88%EB%8B%A4?&mode=hangul",
    tutorials: [{
        active: "inactive",
        name: "Vowels"
    },{
        active: "inactive",
        name: "Consonants"
    },{
        active: "inactive",
        name: "Simple Words"
    },{
        active: "inactive",
        name: "Harder Words"
    }]
},{
	active: "inactive",
	name: "Conjugations",
	tutorials: [{
		active: "inactive",
		name: "ㅗ and ㅏ regular",
		verbs: ["작다", "놀다", "닦다"]
	}, {
		active: "inactive",
		name: "ㅜ, ㅓ and ㅣ regular",
		verbs: ["�?다", "울다", "멀다"]
	}, {
		active: "inactive",
		name: "ㅏ and ㅓ reductive"
	}, {
		active: "inactive",
		name: "ㅗ and ㅜ reductive"
	}, {
		active: "inactive",
		name: "ㅣ reductive"
	}]
}, {
	active: "inactive",
	name: "Sentence Building",
	tutorials: [{
		active: "inactive",
		name: "Particles"
	}, {
		active: "inactive",
		name: "Word Order"
	}]
}];
<!DOCTYPE html>
<html ng-app="Tutorials">
  
  <head lang="en">
    <meta charset="utf-8">
    <title>Custom Plunker</title>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
    <link rel="stylesheet" href="style.css">
    <script src="script-ng.js"></script>
  </head>
  
  <body ng-controller="getAnswers">
    <ul ng-repeat="section in sections" ng-init="sectionIndex = $index">
      <li  class="section_title {{section.active}}" >
          {{section.name}}
      </li>
      <ul>
        <li class="tutorial_title {{tutorial.active}}" ng-click="loadFromMenu(sectionIndex)" ng-repeat="tutorial in section.tutorials">
              {{tutorial.name}}
        </li>
      </ul>
    </ul>
  </body>

</html>

And similar to remaining two Conjugations and Sentence Building. Until and unless I dont click it shoudnt show its nested array

1 Answer 1

1

Do you mean this: ??

angular.module('Tutorials', []).controller('getAnswers', function ($scope, $element) {
    $scope.sectionNumber = 0;
    $scope.tutorialNumber = 0;
  $scope.questionNumber = 0;
	$scope.sections = sections;
	$scope.loadFromMenu = function (tut) {
      alert(tut);
			if (tut === $scope.tutorialNumber && tut !== 0) {
				return;
			} //if clicked on already playing tut
			if (tut !== undefined) {
				$scope.tutorialNumber = tut;
			}
			var section = sections[$scope.sectionNumber];
			for (var i in section.tutorials) {
				section.tutorials[i].active = "inactive";
			}
			section.active = "active";
			section.tutorials[$scope.tutorialNumber].active = "active";
			$scope.$apply();
			$scope.questionNumber = 0;
			if ($scope.sectionNumber === 1){
				conjugationController();
			}
		};

});

var sections = [{
    active: "inactive",
    name: "Reading Korean",
  expand: true,
  romanizeService: "http://www.kawa.net/works/ajax/romanize/romanize.cgi?q=%ED%96%88%EB%8B%A4?&mode=hangul",
    tutorials: [{
        active: "inactive",
        name: "Vowels"
    },{
        active: "inactive",
        name: "Consonants"
    },{
        active: "inactive",
        name: "Simple Words"
    },{
        active: "inactive",
        name: "Harder Words"
    }]
},{
	active: "inactive",
	name: "Conjugations",
	tutorials: [{
		active: "inactive",
		name: "ㅗ and ㅏ regular",
		verbs: ["작다", "놀다", "닦다"]
	}, {
		active: "inactive",
		name: "ㅜ, ㅓ and ㅣ regular",
		verbs: ["�?다", "울다", "멀다"]
	}, {
		active: "inactive",
		name: "ㅏ and ㅓ reductive"
	}, {
		active: "inactive",
		name: "ㅗ and ㅜ reductive"
	}, {
		active: "inactive",
		name: "ㅣ reductive"
	}]
}, {
	active: "inactive",
	name: "Sentence Building",
	tutorials: [{
		active: "inactive",
		name: "Particles"
	}, {
		active: "inactive",
		name: "Word Order"
	}]
}];
<!DOCTYPE html>
<html ng-app="Tutorials">
  
  <head lang="en">
    <meta charset="utf-8">
    <title>Custom Plunker</title>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
    <link rel="stylesheet" href="style.css">
    <script src="script-ng.js"></script>
  </head>
  
  <body ng-controller="getAnswers">
    <ul ng-repeat="section in sections" ng-init="sectionIndex = $index">
      <li  class="section_title {{section.active}}" ng-click="section.expand=!section.expand" >
          {{section.name}}
      </li>
      <ul ng-show="section.expand">
        <li class="tutorial_title {{tutorial.active}}" ng-click="loadFromMenu(sectionIndex)" ng-repeat="tutorial in section.tutorials">
              {{tutorial.name}}
        </li>
      </ul>
    </ul>
  </body>

</html>

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

3 Comments

yes exactly.Thanks for this. Moreover one more thing if you can help. I want by default Reading Korean and child should be shown should be shown. @MeTe-30
@Mohammed I don't know your limits, but adding expand: true to Reading Korean will solve the problem, check the updates.
I want a small change in this. If I click on any section.name then other section.name's tutorial list should be hide and that clicked section.name's tutorial list should display. @MeTe-30

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.