How do I display an option in a paragraph
when a user selects one of the options?
Here is what I have so far:
<select ng-model="model.id" convert-to-number>
<option value="0">Soccer</option>
<option value="1">Basketball</option>
<option value="2">Tennis</option>
<option value="3">Baseball</option>
</select>
<p> Your choice is [user's choice goes here]! </p>
Basically, how would I get it to display a user's choice in a <p>
? And how do I keep it there?
If statements, switches, append? I've been stuck on how to do this
Controller:
.run(function($rootScope) {
$rootScope.model = { id: 2 };
})
.directive('convertToNumber', function() {
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
ngModel.$parsers.push(function(val) {
return parseInt(val, 10);
});
ngModel.$formatters.push(function(val) {
return '' + val;
});
}
};
});