我试图用angularjs,webpack2做模式弹出。如何立即更新角度ui.router嵌套状态?
但是有些问题困扰着我..
我想使具有自定义URL,但
在模式弹出模式弹出,$state.current
仍表示父母的状态。
我搜索onEnter
函数被调用时状态转换是完全做得到。
和其间,模态的状态不更新。 (我认为这就是为什么模态的状态表示父母的状态)
我可以通过setTimeout函数获得模态自己的状态和stateParams,但它只是欺骗对吗?
如何以正确的方式获得模态的状态?
===
这是我的app.js,
// HOME
.state('home', {
url: '/',
templateUrl: 'client/pages/home/home.html',
controller: 'HomeController',
})
// PLAYER MODAL
.state('player', {
url: 'player/:playerName',
parent: 'home',
onEnter: function($stateParams, $state, $uibModal) {
$uibModal.open({
templateUrl: 'client/pages/player/player.html',
resolve: {},
controller: 'PlayerController'
}).result.then(function (result) {
// $scope.$close
alert('result ->' + result);
}, function (result) {
// $scope.$dismiss
alert('dismiss ->' + result);
}).finally(function() {
// handle finally
return $state.go('home');
});
}
});
HomeController中,
angular.module('907degree')
.controller('HomeController', function ($scope, $state) {
$scope.state = $state.current;
$scope.players = ['messi', 'hazard', 'ronaldo'];
$scope.showModal = function (playerId) {
$state.go('player', { playerName: playerId });
};
})
和的PlayerController。
angular.module('907degree')
.controller('PlayerController', ($scope, $http, $state, $stateParams, itemService) => {
$scope.playerState = $state.current;
$scope.params = $stateParams.playerName;
$scope.item = itemService.get($stateParams.id);
$scope.ok = function() {
$scope.$close('clicked OK');
};
$scope.dismiss = function() {
$scope.$dismiss('clicked CANCEL');
};
$scope.checkState = function() {
console.log($state.current, $stateParams);
console.log($scope.playerName);
}
})
我认为我的回购比解决这个问题更好,所以就是这样。
混帐克隆[email protected]/hagfish1210/907degrees.git & NPM安装& NPM运行开发
我觉得我的回购比plunker解决这个问题更好。这就是它。 混帐克隆的https://[email protected]/hagfish1210/907degrees.git &NPM安装 &故宫运行开发 – hagfish1210
如果您正在使用的用户界面路由器1.0,简单的答案是注入'$ $转型'并从它的参数中获取/从状态。 –