我正在开发一个使用 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/