Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 未定义$-jquery角度混合_Angularjs_Jshint - Fatal编程技术网

Angularjs 未定义$-jquery角度混合

Angularjs 未定义$-jquery角度混合,angularjs,jshint,Angularjs,Jshint,以前我用jQuery开发了我的所有项目,但最近开始使用Angular。 我用Yeoman生成器创建了一个有角度的样板,并从中扩展了我的代码 我将ajax表单post jQuery代码翻译成以下Angular控制器 'use strict'; angular.module('MyApp') .controller('ShareformCtrl', function ($scope, $http) { // create a blank object to hold our form infor

以前我用jQuery开发了我的所有项目,但最近开始使用Angular。 我用Yeoman生成器创建了一个有角度的样板,并从中扩展了我的代码

我将ajax表单post jQuery代码翻译成以下Angular控制器

'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应该有权访问
$
,但它没有,或者这里正在发生其他事情。

在代码顶部添加下面的注释以绕过jshint检查

/* global $ */

告诉JSHint不要担心
$
在根项目目录中创建.jshintrc

{
  "globals": {
     "$": false
  }
}

谁在抛出错误提示或浏览器?coode是否在浏览器中工作?我要避免混合使用jQuery和Angular.jshint,因为它会抛出这个错误。您应该创建一个服务作为工厂,以使用$http POST作为方法。然后在控制器中使用该方法。在你的成功中也不需要做if-else语句。将.error()用于错误代码。看看它有多大帮助。不需要$.param($scope.formData)。data:$scope.formData可以正常工作。如果要传入jQuery,请使用“value”向angular injector Ok注册jQuery,这有助于构建它。在我的控制台中,我看到它正在发布,但没有发送数据。您确定
$scope.formData
不是空对象吗?console.log($scope.formData);正在打印出{},所以在post:Syeah上它是空的,所以检查一下为什么关于您的表单它是空的:DDoh!忘记了ng型号,对不起,伙计们:P谢谢你们的帮助,总有一天我会喜欢的。