我有一个在某些事件上动态变化的输入字段。
<input name="selectedId" id="selectedId" ng-model="selectedId" type="hidden" on-change="setUrl">
现在,我想在页面更改时将页面重定向到输入字段中存在的那个 id。
我的控制器:
var app = angular.module("myApp", []).
config(function($routeProvider, $locationProvider) {
$routeProvider.
when("/a1", { templateUrl: "partials/page1.html"}).
when("/a2", { templateUrl: "partials/page2.html"}).
otherwise( { redirectTo: "/a1" });
});
app.controller("MainCtrl", function($scope, $location) {
$scope.setUrl=function($scope){
if ($scope.selectedId) {
alert($scope.selectedId);
}
else{
alert("Out of scope");
}
//$location.path($scope.selectedId);
};
在这里,我无法将输入字段值放入范围。我什至无法触发setUrl()
,以便我可以重定向 URL。
我是 AngularJS 的新手,所以我需要了解这个概念。