Sanitizing User Input in AngularJs v1.5.8

84 views
Skip to first unread message

Ankit R Pandey

unread,
Jul 2, 2018, 6:49:31 AM7/2/18
to Angular and AngularJS discussion
Hi,

I am trying to sanitize user input in my angular application. I went through stackoverflow but there is no help so far. Is there anyone who can help me with that? I will share the code snippet as well if you guys ask me. Thanks in advance.

abhay dhar

unread,
Jul 2, 2018, 7:04:39 AM7/2/18
to Angular and AngularJS discussion
You can use bootstrap for HTML5 frontend validations . What type of input validation or user input sanitize you are looking for ?

Ankit R Pandey

unread,
Jul 2, 2018, 7:21:51 AM7/2/18
to Angular and AngularJS discussion
Here is my code snippet :

<div class="form-group">
                   <label for="videoLocationInput">Location</label>

                    <p class="input-group">
                       <input type="text" autocomplete="on" ng-model="location" placeholder="Location"
                              uib-typeahead-append-to-body="true"
                              uib-typeahead="loc as loc.name for loc in getLocation($viewValue)"
                              uib-typeahead-on-select="setLocation($item, $model, $label)" name="locationInput"
                              uib-typeahead-loading="loadingLocations" uib-typeahead-no-results="noResults"
                              class="form-control">
               <span class="input-group-addon">
                   <i ng-show="loadingLocations" class="fa fa-spinner fa-spin"></i>
                   <i ng-show="noResults" class="fa fa-ban"></i>
                   <i ng-show="!(noResults || loadingLocations)" class="fa fa-check"></i>
               </span>
                   </p>
               </div>

And here is controller file :

$scope.location = null;
       $scope.loadingLocations = false;
       $scope.noResults = true;
       $scope.getLocation = function (val) {
           return mapi.location.autocomplete(val).then(function (response) {
               if (!response.autocomplete) return null;
               return response.autocomplete.filter(function (item) {
                   switch (item.area_type) {
                       case 'city':
                           item.name = item.city + ', ' + item.state_code;
                           break;

                        case 'neighborhood':
                           item.name = item.neighborhood + ", " + item.city + ', ' + item.state_code;
                           break;

                        case 'state':
                           item.name = item.state_code;
                           break;

                        default:
                           return false;
                   }
                   return item;
               });
           });
       };
       $scope.setLocation = function ($item, $model, $label) {
           $scope.video.location_name = $label;
           $scope.video.location = {
               lat: _.get($item, 'centroid.lat', undefined),
               lon: _.get($item, 'centroid.lon', undefined)
           };
           refreshMatchingPlaylists();
       };
Enter code here...


Reply all
Reply to author
Forward
0 new messages