1

In above code data are coming from server side in studentsData. This is an array object and I am adding $scope object with studentsData. In other pages I want to access a data from this json object studentsData. With the help of ng repeat angularjs ng directive here is my code

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script type="text/javascript" src="angular/lib/angular.min.js"></script>
    <script type="text/javascript" src="js/controller/studentsmarks.js"></script>   
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/style.css">
</head>

<body>
    <div id="container">            
        <div id="header">
                    <h1>
                        <span class="black-text">School Management Site</span>
                    </h1>
                </div><!--
                header end
                --><div id="topmenu">
                    <ul>
                        <li>
                            <a href="school_home_page.jsp">HOME</a>
                        </li>
                        <li>
                            <a href="student_info_page.jsp">STUDENTS</a>
                        </li>

                        <li>
                            <a href="class_info_.jsp">CLASSINFORMARION</a>
                        </li>
                        <li>
                            <a href="student_search_info.html">SEARCH</a>
                       </li>
                            <li>
                            <a href="manage_student_marks.html">STUDENTMARKS</a>
                           </li>
                        <li>
                            <a href="logout.jsp">LOGOUT</a>
                        </li>
                    </ul>
                </div><!--
                topmenu end

                --><div id="content">
                    <div ng-controller="studentMarksController"  ng-init="getStudentsInfoMarks()">
                      <form name="studentform" ng-submit="submitStudentForm(studentform.$valid)" novalidate>
                        <label for="name" style="color: blue;">StudentRollNo:</label><br/>

                    <select id="rollId"  name="StudentrollNumber" ng-model="student.rollNumber" style="margin-left: 30px" >
                        <option value="">-- Select RollNo: --</option>
                        <option ng-repeat="StudentrollNumber in studentsData" value="{{StudentrollNumber.rollNumber}}">{{StudentrollNumber.rollNumber}}</option>
                    </select>


                       <div class="form-group">
                        <label for="name" style="color: blue;">PhysicsMarks:</label>
                           <div class="col-sm-12">
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" id="studentPhysicsMarks"
                                        name="studentPhysicsMarks" ng-model="student.studentPhysicsMarks" required
                                        placeholder="PhysicsMarks:">
                                </div>
                                <div class="col-sm-9">
                                    <span style="color: red"
                                        ng-show="studentform.studentPhysicsMarks.$error.required && submitted">
                                        PhysicsMarks  is required.</span>
                                </div>
                           </div>
                         </div>

                           <br/>
                           <br/>

                           <div class="form-group">
                        <label for="name" style="color: blue;">ChemistryMarks:</label>
                           <div class="col-sm-12">
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" id="studentChemistryMarks"
                                        name="studentChemistryMarks" ng-model="student.studentChemistryMarks" required
                                        placeholder="ChemistryMarks">
                                </div>
                                <div class="col-sm-9">
                                    <span style="color: red"
                                        ng-show="studentform.studentChemistryMarks.$error.required && submitted">
                                        ChemistryMarks  is required.</span>
                                </div>
                           </div>
                         </div>
                           <br/>
                           <br/>

                           <div class="form-group">
                        <label for="name" style="color: blue;">MathsMarks:</label>
                           <div class="col-sm-12">
                                <div class="col-sm-3">
                                    <input type="text" class="form-control" id="studentMathsMarks"
                                        name="studentMathsMarks" ng-model="student.studentMathsMarks" required
                                        placeholder="MathsMarks">
                                </div>
                                <div class="col-sm-9">
                                    <span style="color: red"
                                        ng-show="studentform.studentMathsMarks.$error.required && submitted">
                                        MathsMarks  is required.</span>
                                </div>
                           </div>
                         </div>
                         <br/>
                         <br/>
                          <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="submit" class="btn btn-primary">Submit</button>
                            </div>
                           </div>
                 </form>
                  <div class="container">        
                         <table class="table">
                            <tr>
                                <th>StudentRollNo</th>
                                <th>PhysicsMarks</th>
                                <th>ChemistryMarks</th>
                                <th>MathsMarks</th>
                            </tr>
                            <tr class="info" ng-repeat="studentmarks in studentsData">
                                Total Number of Student:<label style="color: black">{{studentsData.length}}</label>
                                        <td>
                                            {{studentmarks.rollNumber}}
                                        </td>
                                        <td>
                                            {{studentmarks.physicsMarks}}
                                        </td>
                                        <td>
                                            {{studentmarks.chemistryMarks}}
                                        </td>
                                        <td>
                                            {{studentmarks.mathMarks}}
                                        </td><!--
                                        <td>
                 <input type="button" class="btn btn-danger" name="Danger" value="Delete" ng-click = "deleteStudent(student.addresId)">
                                        </td>
                                    --></tr>
                        </table>    

                </div>          
                </div>

                </div><!--
                content endss

                --></div><!--

            container end
4
  • You should share the structure of your JSON. Always easier for us with it. Commented Sep 4, 2015 at 15:01
  • $scope.studentsData = data[0]; Commented Sep 4, 2015 at 15:15
  • this is my json object sir Commented Sep 4, 2015 at 15:27
  • What's the question/problem? And what's studentsData? Share a sample of it. Commented Sep 4, 2015 at 15:38

1 Answer 1

1

You need to post your controller code, not just the HTML. But briefly, if you want to share data across multiple pages as you say 1) each page should have its own controller 2) put the code that gets the data in a service, and 3) inject the data service into each controller.

A good intro to service basics is https://www.airpair.com/javascript/posts/services-in-angularjs-simplified-with-examples

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.