【发布时间】:2016-08-22 08:26:06
【问题描述】:
我遇到了一些问题。我编写了通过单击按钮清除输入的函数,但是当我使用 $stateProvider 并且在 state 中实现了清理时它不起作用。
app.js:
<script>
var app = angular.module("app", ['ui.router']);
app.config(function($stateProvider, $urlRouterProvider){
$urlRouterProvider.otherwise("/first");
$stateProvider
.state("first", {
url: "/first",
templateUrl: "first.html"
})
.state("second", {
url: "/second",
templateUrl: "second.html"
});
});
app.controller("ctrl", function($scope){
$scope.searchAll = "";
$scope.clearSearch = function () {
$scope.searchAll = "";
};
});
</script>
页面:
<body ng-controller = "ctrl">
<div class = "container" >
<button type="button" class="btn btn-success"><a ng-href="#/first">First</a></button>
<button type="button" class="btn btn-success"><a ng-href="#/second">Second</a></button>
<br>
<ui-view><ui-view>
</div>
</body>
先声明:
FIRST SIDE!!!!!
<input type="text" class="form-control" ng-model="searchAll"></input>
<a href="" data-ng-click="clearSearch()">X</a>
状态秒:
SECOND SIDE!!!!
【问题讨论】:
-
你为什么要这样做???这么简单,你为什么要在 state 中使用它?
-
我需要在不刷新的情况下更改页面,并且其中一个页面包含必须通过按钮清理的输入。它很简单,但不起作用。
标签: javascript angularjs input angular-ngmodel