我有一个在某些事件上动态更改的输入字段。如何使用angularjs跟踪输入字段值的动态变化
<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()
,因此我可以重定向网址。
我是AngularJS的新手,所以我需要理解这个概念。
它适用于按键事件,但不适用于通过JavaScript的动态值。 – Sumant