[英]Redirect in angularjs using vm
I am trying to redirect to a different route when i submit a form using angularjs and I am getting an error that says 当我使用angularjs提交表单时,我正在尝试重定向到不同的路径,并且我收到了错误消息
Cannot read property 'go' of undefined object
无法读取未定义对象的属性“go”
Below is my form code 下面是我的表格代码
<div class="col-sm-4 col-sm-push-4 margin-top-30">
<form ng-controller="LogonController" data-ng-submit="vm.setDjName()" name="logonForm" novalidate>
<div class="form-group">
<input type="text" name="dj-name" data-ng-model="vm.djName" placeholder="Your DJ Name" class="form-control">
</div>
<button class="btn btn-primary btn-block" data-ng-click="vm.setDjName()" type="button">Login</button>
</form>
</div>
and here is my controller 这是我的控制器
(function () {
'use strict';
angular
.module('app.controllers')
.controller('LogonController', LogonController);
LogonController.$inject = [];
function LogonController ($state) {
var vm = this;
vm.setDjName = function () {
$state.go('/video');
}
}
})();
How would i restructure the code to make the redirect work? 我将如何重组代码以使重定向工作?
I think you have to inject the $state
service: 我认为你必须注入
$state
服务:
LogonController.$inject = ['$state'];
// or
angular
.module('app.controllers')
.controller('LogonController', ['$state', LogonController]);
Take a look at angular dependency injection documentation 看一下角度依赖注入文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.