加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – $未定义 – jquery角度混合

发布时间:2020-12-17 07:08:36 所属栏目:安全 来源:网络整理
导读:以前我用jQuery开发了所有项目,但最近开始使用Angular. 我用Yeoman生成器创建了一个Angular样板,并从中扩展了我的代码. 我将jQuery代码的ajax表单翻译成以下Angular控制器. 'use strict';angular.module('MyApp').controller('ShareformCtrl',function ($sco
以前我用jQuery开发了所有项目,但最近开始使用Angular.
我用Yeoman生成器创建了一个Angular样板,并从中扩展了我的代码.

我将jQuery代码的ajax表单翻译成以下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上失败

在我的索引中,我实现了如下角度和jquery:

<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>

所以Angular应该可以访问$,但它没有或其他东西在这里发生.

解决方法

告诉JSHint不要担心根项目目录中的$create .jshintrc

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

Docs

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读