我正在尝试通过在我的一个注入的HTML页面中使用提交按钮来重定向页面。但在我点击提交按钮后,它将无法正常工作。我从“控制台”看到了这个错误。有人可以帮忙吗?
angular.js:12477 TypeError: Cannot read property 'path' of undefined
at loginCtrl.onSubmit (LoginController.js:112)
at fn (eval at compile (angular.js:13322), <anonymous>:4:258)
at callback (angular.js:23549)
at Scope.$eval (angular.js:15989)
at Scope.$apply (angular.js:16089)
at HTMLFormElement.<anonymous> (angular.js:23554)
at HTMLFormElement.eventHandler (angular.js:3298)
scotchApp.controller('loginCtrl', ['$location', function loginCtrl(formlyVersion, $location) {
var lg = this;
lg.onSubmit = onSubmit;
lg.model = {};
lg.fields = [
];
function onSubmit() {
alert('1');
$location.path('/about');
}
}]);
<div>
<form ng-submit="lg.onSubmit()" novalidate>
<formly-form form="exampleForm" model="lg.model" fields="lg.fields">
<button type="submit" class="btn btn-primary submit-button">Submit</button>
</formly-form>
</form>
</div>
答案 0 :(得分:1)
在这种情况下,您的$location
注入被错误的参数替换,请将其更改为:
["$location", " formlyVersion ", function ($location, formlyVersion ){}]
未定义是因为 formlyVersion 没有path
。
答案 1 :(得分:0)
代替$ location尝试使用$ state.go('state',{},{reload:'state'});