如何從AngularJS的另一個控制器調用ui-view
這是我的示例程序。其實在這裏我使用嵌套的ui-view。問題是,當我點擊提交 按鈕,最初它工作正常,並在SampleController中顯示警報
但我再次點擊它wwithout刷新頁面,它不去SampleController爲什麼?
我需要去該控制器當我點擊提交按鈕
是它在我的code.Please任何錯誤檢查我stateProvider too.I我在AngularJS一個新的啓動器
普萊舍指正謝謝...
var app=angular.module('TestApp', ['angular.filter','ui.router']);
app.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('category', {
views : {
"body" : {
url : '/category',
templateUrl : 'category.html',
controller : 'TestController'
}
}
})
.state('category.subcategory', {
url : '/subcategory',
views : {
"[email protected]" : {
templateUrl : 'sample.html',
controller : 'SampleController'
}
}
})
});
app.controller('MainController', MainController);
function MainController($scope,$state) {
alert("This is MainController")
$scope.getCategory=function(){
$state.go('category');
}
}
app.controller('TestController', TestController);
function TestController($scope, $state){
$scope.getData=function() {
alert("Call to Sample Controller")
$state.go('.subcategory');
}
}
app.controller('SampleController', SampleController);
function SampleController($scope,$state) {
alert("This is SampleController")
}
這是我的樣本HTML文件
的index.html
<!DOCTYPE html>
<html ng-app="TestApp">
<head>
<link rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular-route.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-filter/0.5.8/angular-filter.js"></script>
<script src="angular-ui-router.js"></script>
<script src="script.js"></script>
</head>
<body ng-controller="MainController">
<a href="#" ng-click="getCategory()">Click to Category</a>
<div ui-view="body">
<div ui-view="subbody"></div>
</div>
</body>
</html>
category.html
<div>
<input type="button" name="button" id="button" value="Submit" ng-click="getData()" />
<div ui-view="subbody"></div>
</div>
sample.html
<div>
Sample Controller
</div>
我需要打SampleController當我點擊提交按鈕
在我的項目,提交按鈕部分包含兩個選擇框類和子類別。基於那種類型 和子類別我需要顯示SampleController.So刷新只能由SampleController完成的細節。
有你在''state.go'中試過'category.subcategory'而不是'.subcategory'? –
@Symon kt2:檢查鏈接http://stackoverflow.com/questions/19516771/state-go-toparams-not-passed-to-stateparams它可能是有用的喲。 – lalitpatadiya
@Martijn Welker我試過先生,但沒有工作 –