之前我使用 jQuery 开发了所有项目,但最近开始使用 Angular。 我使用 Yeoman 生成器创建了一个 Angular 样板,并从中扩展了我的代码。
我将我的 ajax 表单 post jQuery 代码转换为以下 Angular Controller 。
'use strict';
angular.module('MyApp')
.controller('ShareformCtrl', function ($scope, $http) {
// create a blank object to hold our form information
// $scope will allow this to pass between controller and view
$scope.formData = {};
// process the form
$scope.processForm = function() {
$http({
method : 'POST',
url : 'php/share_handling.php',
data : $.param($scope.formData), // pass in data as strings
headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload)
})
.success(function(data) {
console.log(data);
if (!data.success) {
// if not successful, bind errors to error variables
$scope.errorName = data.errors.name;
$scope.errorSuperhero = data.errors.superheroAlias;
} else {
// if successful, bind success message to message
$scope.message = data.message;
}
});
};
});
但是 jshint 将在 $.param
上失败
在我的索引中,我实现了 Angular 和 jquery,如下所示:
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
所以 Angular 应该可以访问 $
,但它没有,或者这里发生了其他事情。
最佳答案
关于angularjs - $ 未定义 - jquery Angular 混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27704413/