JavaScript Should we use jQuery with AngularJS? [closed]

Good thing about AngularJS which you need consider before doing Migration.

  1. It provides two way binding by only storing variable in scope.
  2. Other thing we need write code as compare to JQuery.
  3. Implementation in modular way(by creating angular.module)
  4. Shift most of the code from Javascript to HTML, that looks code more cleaner.
  5. Singleton patterners are there to store a data & share it between multiple controller or services.
  6. It in built with smaller version of jQuery that is known as JQlite which has most of the basic functionality, but you want to use JQuery in AngularJS then it will be available easily just you need to add jQuery reference in it, after that JQLite functionality gets converted into JQuery.

You should not use jQuery on the top of the AngularJS, because AngularJS digest cycle wont run if we do any angular DOM manipulation or scope variable manipulation using JQuery.

As you migrate you jQuery component to AngularJS you need to follow below things

  1. You need first search angular-ui-bootstrap site because they had covered most of the UI component which has already converted to angular.
  2. I'm sure you will not found every plugin Angular version, at that you should wrap that plugin to directive. Which will give you controller over the DOM element where ever directive has placed.(Example here for Datepicker using directive)
  3. Don't try to bind event from outside angular context that will create a digest cycle, that will leads to affect in binding updation on UI.
  4. Ensure while making any ajax call that should be using $http rather than using $.ajax
  5. There are many places you can find in jquery code that would be replace by ng-class directive, like if you are doing only adding & removing class, or showing some element on basis of any condtion, so that sort of jquery code can be replace by use ng-class directive
  6. Look for the places where you are only removing a DOM or adding DOM that could be easily replaced by the the ng-if directive, or only show hide of element can be done by using either ng-show/ng-hide
  7. Also find such a part in UI in which you are creating same DOM using for loop that can be convert to angular native directive ng-repeat
  8. If you have any case where you wanted to show and hide multiple element, so that part of code would be implemented using ng-switch directive
Answer:1

Use Angular to build up controllers and API clients, then as time permits move as much DOM manipulation and as possible to angular directives. Then wait for Angular 2 to be released and do it all over again.

Answer:2

I have the following code : var fomattedDate = moment(myDate).format("L"); Sometimes moment(myDate).format("L") returns "Invalid date", I want to know if there is a way to prevent that and return an ...

I have the following code : var fomattedDate = moment(myDate).format("L"); Sometimes moment(myDate).format("L") returns "Invalid date", I want to know if there is a way to prevent that and return an ...

I'm using a simple custom directive for a modified input field which occurs throughout my application: app.directive('editor', function() { return { restrict: 'E', templateUrl: '...

I'm using a simple custom directive for a modified input field which occurs throughout my application: app.directive('editor', function() { return { restrict: 'E', templateUrl: '...

  1. angularjs custom directive input validation
  2. angularjs custom directive input
  3. angularjs directive input validation

I want to know if its possible to have tooltip on a collapse anchor tag. The code which is use for collapse is: <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">Data</...

I want to know if its possible to have tooltip on a collapse anchor tag. The code which is use for collapse is: <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">Data</...

Background: I am compiling 2 dependent TypeScript files to js, which produces also source maps (one source map per file) using tsc 1.0 I'm using -m commonjs and then use browserify to generate a ...

Background: I am compiling 2 dependent TypeScript files to js, which produces also source maps (one source map per file) using tsc 1.0 I'm using -m commonjs and then use browserify to generate a ...