<!DOCTYPE html>
<html ng-app="splessonsApp">
<head lang="en">
<meta charset="utf-8">
<title>SPLessons</title>
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" type="text/css">
</head>
<body ng-controller="splessonsController">
<br/>
<br/>
<div class="container">
<div class="jumbotron">
<h3> <a href="http://www.splessons.com/2015/05/how-to-use-ng-option-to-set-default-value-of-select-element/" > SPLessons.com </a> </h3>
<form class="form-horizontal" name="form_add_questions">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Degrees in Array: </label>
<div class="col-sm-10">
<select name="degreeinagrray" class="form-control" ng-model="addQuestion.selecteddegreeobjectarray" >
<option value=""> Select Type </option>
<option value="Essay"> Essay </option>
<option value="Multiple"> Multiple Questions </option>
<option value="Question"> Question</option>
<option value="SubQuestion"> Sub Question</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Degree in Object: </label>
<div class="col-sm-10">
<select name="selecteddegreeobject" class="form-control" ng-model="addQuestion.selecteddegreeobject" ng-options="degree.degree_name for degree in degreesobject track by degree.degree_code" >
<option value=""> Select Degree </option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Degree in Object: </label>
<div class="col-sm-10">
<input type="text" ng-model="addQuestion.testing" class="form-control">
<textarea ng-model="addQuestion.testtext" name="testtext" class="form-control"> </textarea>
</div>
</div>
</form>
<a ng-click="resetFormFlag(form_add_questions)" class="btn btn-danger btn-xs pull-right"> Add <i class="glyphicon glyphicon-plus"></i> </a>
<p> Selected value in Array : {{addQuestion.selecteddegreeobjectarray}}</p>
<p> Selected value in Object : {{addQuestion.selecteddegreeobject.degree_name}}</p>
</div>
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular.min.js" type="text/javascript" ></script>
<script src="app.js" type="text/javascript"></script>
</body>
</html>
// Code goes here
/* Styles go here */
/**
* Created by sinukoll on 4/15/15.
*/
'use strict';
var splessonsApp = angular.module('splessonsApp',[]);
splessonsApp.controller("splessonsController",function($scope){
$scope.addQuestion = {};
$scope.addQuestion={ selecteddegreeobjectarray : "SubQuestion",
selecteddegreeobject : {degree_code:"GR"},
testing : "Sreehari",
testtext : "sreehari"
};
// working with ng-options with Array data
/* $scope.degreesarray = ["GB","GR"];
$scope.addQuestion.selecteddegreeobjectarray = "GB";*/
// working with ng-options with Json data
$scope.degreesobject = [
{"degree_code":"GB","degree_name":"Bachelor of Science"},
{"degree_code":"GR","degree_name":"Non Degree Undergraduate"}
];
$scope.addQuestion.selecteddegreeobject = {degree_code:"GB"};
$scope.resetFormFlag = function(form_add_questions){
if(form_add_questions)
{
form_add_questions.$setPristine();
}
//$scope.addQuestion.selecteddegreeobject = {degree_code:"GB"};
};
});