Ionic navbar search

Html:

<search-bar ng-model="search"></search-bar>

app.js:

.directive('searchBar', [function () {
  return {
    scope: {
      ngModel: '='
    },
    require: ['^ionNavBar', '?ngModel'],
    restrict: 'E',
    replace: true,
    template: '<ion-nav-buttons side="right">'+
            '<div class="searchBar">'+
              '<div class="searchTxt" ng-show="ngModel.show">'+
                  '<div class="bgdiv"></div>'+
                  '<div class="bgtxt">'+
                    '<input type="text" placeholder="Search..." ng-model="productObject.searchAgenda">'+
                  '</div>'+
                '</div>'+
                '<i class="button button-clear" ng-class="{\'icon-disabled-opacity\' : showdate}" ng-click="updateSelection();" title="Show all dates">All</i>'+
            '</div>'+
          '</ion-nav-buttons>',
   
    compile: function (element, attrs) {
      var icon=attrs.icon
          || (ionic.Platform.isAndroid() && 'ion-android-search')
          || (ionic.Platform.isIOS()     && 'ion-ios7-search')
          || 'ion-search';
      angular.element(element[0].querySelector('.icon')).addClass(icon);
     
      return function($scope, $element, $attrs, ctrls) {
        var navBarCtrl = ctrls[0];
        $scope.navElement = $attrs.side === 'right' ? navBarCtrl.rightButtonsElement : navBarCtrl.leftButtonsElement;
       
      };
    }
   
  };
}])

yourCTRL.js:

app.controller('searchBarCtrl', function($scope,$ionicNavBarDelegate){
  var title, definedClass;
  $scope.$watch('ngModel.show', function(showing, oldVal, scope) {
    if(showing!==oldVal) {
      if(showing) {
        if(!definedClass) {
          var numicons=$scope.navElement.children().length;
          angular.element($scope.navElement[0].querySelector('.searchBar')).addClass('numicons'+numicons);
        }
       
        title = $ionicNavBarDelegate.getTitle();
        $ionicNavBarDelegate.setTitle('');
      } else {
        $ionicNavBarDelegate.setTitle(title);
      }
    } else if (!title) {
      title = $ionicNavBarDelegate.getTitle();
    }
  });
});


15 comments:

  1. Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.Nice article i was really impressed by seeing this article, it was very interesting and it is very useful for me.
    Angularjs Training In Hyderabad

    ReplyDelete
  2. The combination of technologies like JavaScript, NodeJS, PHP, Angular, Ionic, and React is very powerful for building modern applications with high performance and flexibility. Similarly, Oracle Fusion HCM Online Training equips professionals with the right practical knowledge and skills to handle complex cloud-based HR processes, making it highly valuable for career growth in today’s IT landscape.
    Oracle Fusion HCM Online Training

    ReplyDelete
  3. If you're looking for top-quality dental treatment in Nizampet, Nizampet Dentist is your premier destination. Led by the skilled Dr. Sri Lakshmi, the clinic offers comprehensive services—ranging from root canal therapy and dental implants to braces, cosmetic dentistry, and children’s dental care. With modern equipment like 3D imaging, digital X-rays, and a patient-first approach, they deliver comfortable, effective, and personalized care for every smile.
    best dental hospital nizampet

    ReplyDelete
  4. Looking for a strong and natural way to replace missing teeth? Dental implant treatment in Nizampet offers a safe and long-lasting solution. At Nizampet Dentist, skilled implant specialists use advanced technology to give you a confident smile. Implants look and feel like real teeth and help protect your jawbone. Book a consultation to get your personalized treatment plan today.
    dental implant treatment in nizampet

    ReplyDelete
  5. Root Canal Treatment in Nizampet helps save damaged or infected teeth instead of removing them. At Nizampet Dentist, expert dentists use advanced and painless methods to clean and protect the tooth. This treatment relieves pain, stops infection, and keeps your natural smile safe for years.
    Root Canal Treatment in Nizampet

    ReplyDelete
  6. Invisalign providers in Nizampet offer clear, removable aligners that gently move your teeth into the right position. At Nizampet Dentist, skilled orthodontists create custom treatment plans using advanced 3D scans. Invisalign is comfortable, nearly invisible, and perfect for improving your smile without metal braces.
    invisalign providers in nizampet

    ReplyDelete
  7. Invisible Aligners Treatment in Nizampet offers a clear and comfortable way to straighten teeth. At Nizampet Dentist, expert dentists use advanced 3D scans to create custom aligners that gently move your teeth into place. They are removable, painless, and perfect for busy teens and adults. Start your journey to a confident smile today.
    invisible aligners treatment in nizampet

    ReplyDelete
  8. The combination of JavaScript, NodeJS, PHP, Angular, Ionic and React provides a strong tech stack for building fast, scalable and user-friendly web and mobile applications. These technologies streamline both front-end and back-end development, helping developers create modern digital solutions efficiently. Along with using this tech stack, developers can also explore the 9 Best GPL Sites for WordPress Plugins and Themes (2025), where Webjinnee stands out by offering premium plugins and themes at very affordable prices—great for improving project quality while reducing development costs.
    9 Best GPL Sites for WordPress Plugins and Themes (2025)

    ReplyDelete
  9. nice information thanks for sharing this article very useful for me.
    thailand vps hosting

    ReplyDelete
  10. Thank you for posting this—your article provided useful details I really needed.
    hong kong vps server

    ReplyDelete
  11. Thanks for sharing this useful information—it really helped.
    italy vps server

    ReplyDelete
  12. Thanks for sharing this useful information
    vps korea

    ReplyDelete
  13. Thank you for sharing such a great blog. I truly appreciate your effort—keep them coming!
    korea vps server

    ReplyDelete