我在表单上使用ng-submit将数据推送到Firebase,一切都按预期方式运行.我想做的是同时改变观点.在提交按钮本身,我已经点击设置以使用$location执行一个功能.如果我将changeView函数放在.controller方法中,我不能使用$location(具体来说,它说 – “错误:’undefined’不是一个对象(评估’$location.path’)).任何帮助都将是超级复数.
原文链接:https://www.f2er.com/angularjs/143254.html// This doesn't work and throws the error myApp.controller('CtrlName',['$scope','angularFireCollection',function($scope,angularFireCollection,$location) { $scope.changeView = function(view) { $location.path(view); } } ]); // This works as expected,but I'm name spacing my functions globally and I will have to change how I'm accessing my Firebase,which isn't really desired. function CtrlName($scope,$location) { $scope.changeView = function(view) { $location.path(view); } }
这是我的模板:
<form role="form" ng-submit="tactics.add(tactic)"> <div class="form-group"> <label>Select Method</label> <select class="form-control" ng-model="tactic.type"> <option>Email</option> <option>Display</option> <option>SMS</option> <option>Print</option> </select> </div> <button type="submit" class="btn btn-success" ng-click="changeView('/my-tactics')">Save</button> </form>