0

I'm trying to write a jQuery function in AngularJs. I've never done this before. Please could anyone point me in the right direction on what would be the best way to do this?

Thank you.

  $(function() {

  $('.input input').focus(function() {

  $(this).parent('.input').each(function() {
     $('label', this).css({
        'line-height': '18px',
        'font-size': '18px',
        'font-weight': '100',
        'top': '0px'
     });
     $('.spin', this).css({
        'width': '100%'
     });
  });
});
1313
  • 115
  • 1
  • 1
  • 9
  • Look at using a directive to add that function. [AngularJS Developer Guide -- directives](https://docs.angularjs.org/guide/directive). – georgeawg Feb 08 '16 at 01:48
  • Also look at [How to do loading spinners, the Angular way](http://codetunnel.io/how-to-do-loading-spinners-the-angular-way/). – georgeawg Feb 08 '16 at 01:56
  • Ok, will do that - thank you very much : ) – 1313 Feb 08 '16 at 22:00

1 Answers1

0

jQuery is a library that helps to manipulate the DOM, while Angular is a framework which can be used to develops single page applications (see Framework vs Library)

You cannot convert a function that relies on jQuery, in order to use it in an Angular application.

I would strongly suggest you to learn the basis of Angular with a simple guide or video and then tries to implement the feature you have in an angular app.

On a sidenote, it is perfectly possible to use jQuery with Angular, as stated in their documentation. Angular itself uses a subset of jQuery, internally called jQLite.

Community
  • 1
  • 1
zoom
  • 1,686
  • 2
  • 16
  • 27
  • "You cannot convert a function that relies on jQuery, in order to use it in an Angular application." - Why not? – Andrew Shepherd Feb 07 '16 at 21:47
  • My sentence is a bit unclear.. I was trying to say that, as both jQuery and Angular provides different features, code using jQuery cannot be directly converted to its angular equivalent, and vice versa. An existing jQuery code must be integrated into an Angular app, by reasoning in terms of the feature to migrate could fit with the features that Angular provides. – zoom Feb 07 '16 at 21:58
  • Edit (rephrasing last sentence): An existing jQuery code must be integrated into an Angular app, by reasoning in terms of how the feature to migrate could fit within the Angular framework. – zoom Feb 07 '16 at 22:04
  • Ok thanks very much - I've had a look and understand the differences. I didn't realize this at first. Thanks for your advice, I appreciate it. – 1313 Feb 08 '16 at 22:01