$state.go不在AngularJS中工作?
如何在AngularJS中从另一个控制器调用ui视图 这是我的示例程序。实际上在这里我使用的是嵌套的ui视图。问题是,当我最初单击submit按钮时,它工作正常,并显示alert SampleController 但我再次点击了它,但它没有进入SampleController为什么 当我点击提交按钮时,我需要转到那个控制器 我的代码有错误吗?请检查我的状态提供程序。我是AngularJS的新手 请纠正我谢谢你$state.go不在AngularJS中工作?,angularjs,angularjs-scope,Angularjs,Angularjs Scope,如何在AngularJS中从另一个控制器调用ui视图 这是我的示例程序。实际上在这里我使用的是嵌套的ui视图。问题是,当我最初单击submit按钮时,它工作正常,并显示alert SampleController 但我再次点击了它,但它没有进入SampleController为什么 当我点击提交按钮时,我需要转到那个控制器 我的代码有错误吗?请检查我的状态提供程序。我是AngularJS的新手 请纠正我谢谢你 var app=angular.module('TestApp', ['angular
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 : {
"subbody@category" : {
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>
</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,请尝试以下操作:
app.controller('TestController', TestController);
function TestController($scope, $state){
$scope.getData=function() {
alert("Call to Sample Controller")
$state.go('category.subcategory', null, {reload:true});
}
}
此行应为$state.go('category.subcategory');你必须在全州通过考试name@adeel_s是的,我改变了,但它只会在最初再次工作,我改变了我的子类别,它不会工作,因为你没有给它任何状态参数。你的类别有id吗?然后可以执行类似.state('category.subcategory')的操作,{url:'/subcategory/:id'@Nirmal Borkar Yeae它只会工作obe Niraml Ji这又是个问题我更改了我的子类别如果不刷新整个page@ojuskulkarni Yeae它只会在一开始起作用这也是问题所在我更改了我的子类别如果不刷新整个页面它将无法工作