json - Unable to get around with ng-controller -


i beginner angularjs trying build template using it.

my points.html page this:

          <form ng-app="stdapp"  ng-submit="save()" ng-controller="submissioncontroller">                  <div class="select">                     <label> select student </label>                     <select ng-options="student.name student in students" ng-model="student"></select>                 </div>                 <div class="checkbox">                     <label ng-repeat="behavior in behaviors">                       <input type="checkbox" ng-model="behavior"> {{behavior.name}}                     </label>                 </div>                 <div>                     <button type="button" class="btn btn-info">mark</button>                 </div>             </form> 

and points.js looks this:

 var app = angular.module('stdapp', []); app.controller('submissioncontroller', function($scope, $http) {     $scope.save = function() {         console.log($scope.student);         console.log($scope.behavior); };  $http.get("/manager/api/std/useraccount/").success(function(response) {     $scope.students = response.objects; }).error(function() {     alert("an unexpected error occured"); });  $http.get("/manager/api/std/behavior/").success(function(response) {     $scope.behaviors = response.objects; }).error(function() {     alert("an unexpected error occured"); }); }); 

these apis working fine , data server in json format. response first api call :-

{     "meta": {         "limit": 20, "next": null, "offset": 0, "previous": null, "total_count": 3},      "objects": [         {"age": 12, "clas": 5, "id": "559f55347abead2404a61563", "name": "harish", "resource_uri": "/manager/api/std/useraccount/559f55347abead2404a61563/", "studentid": 1},          {"age": 13, "clas": 5, "id": "559f555a7abead2404a61564", "name": "zaya", "resource_uri": "/manager/api/std/useraccount/559f555a7abead2404a61564/", "studentid": 2},          {"age": 11, "clas": 5, "id": "559f556f7abead2404a61565", "name": "harsha", "resource_uri": "/manager/api/std/useraccount/559f556f7abead2404a61565/", "studentid": 3}     ] } 

and json reply second is

{ "meta": {"limit": 20, "next": null, "offset": 0, "previous": null, "total_count": 3},  "objects": [     {"id": "559f560b7abead2404a61566", "name": "doing homework", "points": 3, "resource_uri": "/manager/api/std/behavior/559f560b7abead2404a61566/"},      {"id": "559f56227abead2404a61567", "name": "disrrupting class", "points": -2, "resource_uri": "/manager/api/std/behavior/559f56227abead2404a61567/"},              {"id": "559f56337abead2404a61568", "name": "helping", "points": 5, "resource_uri": "/manager/api/std/behavior/559f56337abead2404a61568/"}]} 

but still i'm not able render received object array in template.

i wrote form in end want submit selected data, want know how can write submit ($http.post()) in case.

can please me, i've tried google examples got either high level or basic.

template won't render unless add ngmodel directive. required attributed because binding data form controls makes no sense without mechanism data further processing (submission).

your html should this:

    <div class="select" ng-controller="pointspagecontroller">         <label> select student </label>         <select ng-options="student.name student in students" ng-model="student.name"></select>     </div> 

however 1 problem. need make sure next things:

  1. put html common controller ng-controller="submissioncontroller" define function used submit handler:

    app.controller('submissioncontroller', function($scope) {     $scope.save = function() {         console.log($scope.student);     }; }); 
  2. add ngsubmit directive on form:

    <form ng-app="stdapp" ng-submit="save()" ng-controller="submissioncontroller">     <!-- ... --> </form> 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -