angularjs - 如何访问 Angular 1.6/es6 应用程序上的表单对象?

标签 angularjs angularjs-scope ecmascript-6 es6-class

我正在开发一个使用 Angular 1.6 和 es6 的应用程序。 我有一个表格:

<form name="foobar" ng-submit="$ctrl.submitThat()"  novalidate>

在submitThat()函数中,我想访问表单对象并检查其验证状态,但它似乎在$scope对象上不可用。 $scope 对象存在,我确保将其作为 Controller 类构造函数的参数传递,但它没有“foobar”属性(表单名称)。

class StuffController {
/*@ngInject*/
constructor($translate, StuffService, $log, $interval, $scope) {
    this.$translate = $translate;
    this.StuffService= StuffService;
    this.$log = $log;
    this.$interval = $interval;
    this.$scope = $scope;
    //more unrelated code
}
submitThat(){
   console.log(this.$scope);//outputed object misses the foobar property
    }
}

我忘了补充一点,该应用程序使用 webpack。

最佳答案

验证对象现在是一个属性,不再是字符串。 所以我不得不更换:

<form name="foobar" ng-submit="$ctrl.submitThat()"  novalidate>

与:

<form name="$ctrl.foobar" ng-submit="$ctrl.submitThat()"  novalidate>

然后它就可以在 $ctrl 对象的 Controller 中使用。

这个框架会不断改变一些小事情,这样我就可以度过愉快的下午。

关于angularjs - 如何访问 Angular 1.6/es6 应用程序上的表单对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42436748/

相关文章:

javascript - Phaser 中的游戏 - AngularJS 中的 JavaScript 和事件

AngularJS:ngRoute 不工作

javascript - 防止 Angular 自定义指令模板中禁用的树节点上的单击事件

javascript - Angular ngGrid 在页面加载时选择行

javascript - 为什么这里要大写 React 呢?从 'react' 导入 * 作为 React

javascript - $rootScope 与服务 - Angular JS

javascript - Angular - 更新模板中的徽章编号

javascript - 为什么这个 Angular 值没有更新?

javascript - 如果字段不为空,请勿在提交时验证 Formik 和 Yup 中未触及的字段

javascript - 如何在 react 组件中添加滚动事件