0

I intend on using Angular for some front end stuff, but using it for Ajax with PHP files the code becomes more verbose compared to jquery.

for example

app.controller('sign_up', function ($scope, $http) {
    /*
    * This method will be called on click event of button.
    * Here we will read the email and password value and call our PHP file.
    */
    $scope.check_credentials = function () {

        document.getElementById("message").textContent = "";

        var request = $http({
            method: "post",
            url: window.location.href + "login.php",
            data: {
                email: $scope.email,
                pass: $scope.password
            },
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        });
        /* Check whether the HTTP Request is successful or not. */
        request.success(function (data) {
            document.getElementById("message").textContent = "You have login successfully with email "+data;
        });
    }
});

And then you need to decode json etc. So if I use jquery for AJAX and angular for everything else, there won't be any conflicts or anything?

Thanks

xsami
  • 1,312
  • 16
  • 31
Vegan Sv
  • 335
  • 2
  • 4
  • 17
  • Please take a look at [“Thinking in AngularJS” if I have a jQuery background?](http://stackoverflow.com/questions/14994391/thinking-in-angularjs-if-i-have-a-jquery-background) AngularJS doesn't completely replace jQuery, but in most cases, there is a different method of doing the same thing without directly using jQuery. – Qantas 94 Heavy Apr 06 '15 at 00:59
  • Your question seems incomplete. You should show the equivalent jquery version of your code. I question the assertion that the jquery version will be significantly less verbose. I might add that your use of "document.getElementById" is not required in angular. – Cerad Apr 06 '15 at 01:05
  • you can build smaller, more re-usable pieces using either framework. – dandavis Apr 06 '15 at 02:16

2 Answers2

1

You may not know but Angular operates on a JQuery library (uses as default the subset of jQuery calles jQLite if no jQuery import has been specified) so you can easily import the jQuery library and use it for your ajax call

AdamM
  • 191
  • 1
  • 6
1

Im a huge fan of Angular, JQuery, Bootstrap, AngularUI and jinqJs

They all have there purposes. Angular has become very popular for the UI and is even better using AngularUI. Mixed with Bootstrap I find I code less and my sites look better. JQuery so I can query the DOM and I use jinqJs to query javaScript data like I would using SQL like expressions. I havent had any issue using all frameworks together. The service in this case is PHP but of course it could be a .Net Web API too. As long as the data format is JSON for example using a predefined structure then what you use for front end and back end are non impacting to each other.

NYTom
  • 524
  • 2
  • 14