AngularJS ng-click功能转到URL

时间:2014-07-06 01:12:35

标签: javascript angularjs

成为AngularJS的新手并开始一个新项目我需要一个解决方案,解决为什么表单取消按钮上的ng-click没有重定向到我设置的视图。从我在其他类似问题中读到的内容来看,它应该可行。可能出现什么问题?

HTML

 <button type="button" class="btn btn-cancel" data-ng-click="programEditCancel('/program-details')">
 <i class="fa fa-times"></i> cancel
</button>

JS

configAppControllers.controller('programEditFormCtrl', ['$scope', '$location', function ($scope, $http, $location) {

        $scope.programEditCancel = function (path) {
            $location.path(path);
        }
    }
]);

1 个答案:

答案 0 :(得分:0)

问题解决了!!问题是因为路由使用ID只是试图回到#/ program-details不是有效的URL我将代码更改为 数据-NG单击=&#34; programEditCancel(&#39; /节目细节/:organizationId /:programId&#39;)&#34;

和Voila,一切都很好!

感谢您的帮助!