user3038625 user3038625 - 2 months ago 6
AngularJS Question

convert returned value from ng-model

i wrote this angularjs code but the problem is when i make the input type to number every thing is ok and the number converted to hexa even i make change the number manually without increase or decrease buttons , but when i make input type to text the result is just same number of text input without converted it.
why ?? and sorry for my english !!

this is my code :

<title> convert to hex </title>
<script src=" /angular.min.js"></script>


<div ng-app="myapp" ng-controller="namectrl">
<input ng-model = 'number' type="text">
<h3> {{hexa(number)}} </h3>

var app = angular.module("myapp" ,[]);
app.controller("namectrl" , function($scope)
$scope.hexa = function(x) {
return x.toString(16);



Try this,

 $scope.hexa = function(x) {
          return Number(x).toString(16);

Working App