我打算使用Angular進行一些前端工作,但將其用於Ajax和PHP文件,與jquery相比,代碼變得更加冗長。組合不同的Javascript框架有什麼缺點嗎?
例如
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;
});
}
});
然後你需要解碼JSON等。所以,如果我使用AJAX jQuery和角度的一切,不會有任何衝突或什麼?
感謝
請看看[「在AngularJS中的思維」,如果我有一個jQuery背景?](http://stackoverflow.com/questions/14994391/thinking-in-angularjs-if-i-have-a-jquery -background)AngularJS不能完全替代jQuery,但在大多數情況下,有一種不用直接使用jQuery來做同樣事情的不同方法。 – 2015-04-06 00:59:10
您的問題似乎不完整。你應該顯示你的代碼的等價jQuery版本。我質疑jquery版本將明顯不那麼冗長的斷言。我可能會補充說,在角度中不需要使用「document.getElementById」。 – Cerad 2015-04-06 01:05:02
您可以使用任一框架構建更小,更可重用的作品。 – dandavis 2015-04-06 02:16:11