Dar*_*ght 7 javascript angularjs angular-ui-bootstrap angular-ui-router
我试图做的基本上是在这里回答无法打开引导模态窗口作为路线
然而,我的解决方案是行不通的.我收到一个错误
Error: [$injector:unpr] Unknown provider: $modalProvider <- $modal
My app has the ui.bootstrap module injected - here is my application config
var app = angular.module('app', ['ui.router', 'ui.bootstrap','ui.bootstrap.tpls', 'app.filters', 'app.services', 'app.directives', 'app.controllers'])
// Gets executed during the provider registrations and configuration phase. Only providers and constants can be
// injected here. This is to prevent accidental instantiation of services before they have been fully configured.
.config(['$stateProvider', '$locationProvider', function ($stateProvider, $locationProvider) {
// UI States, URL Routing & Mapping. For more info see: https://github.com/angular-ui/ui-router
// ------------------------------------------------------------------------------------------------------------
$stateProvider
.state('home', {
url: '/',
templateUrl: '/views/index',
controller: 'HomeCtrl'
})
.state('transactions', {
url: '/transactions',
templateUrl: '/views/transactions',
controller: 'TransactionsCtrl'
})
.state('login', {
url: "/login",
templateUrl: '/views/login',
controller: 'LoginCtrl'
})
.state('otherwise', {
url: '*path',
templateUrl: '/views/404',
controller: 'Error404Ctrl'
});
$locationProvider.html5Mode(true);
}])
Run Code Online (Sandbox Code Playgroud)
我已将控制器缩减为以下内容:
appControllers.controller('LoginCtrl', ['$scope', '$modal', function($scope, $modal) {
$modal.open({templateUrl:'modal.html'});
}]);
Run Code Online (Sandbox Code Playgroud)
最终,我希望实现的是当需要登录时实际上并不是登录页面,而是打开一个对话框.
我也尝试onEnter在ui-routerstate方法中使用该函数.无法使这个工作.
有任何想法吗?
UPDATE
好的 - 事实证明,同时使用ui-bootstrap.js和ui-bootstrap-tpls打破了这一点 - 在阅读文档之后我认为你需要模板来使用ui-bootstrap.虽然似乎所有的掠夺者只在.tpls文件中加载 - 一旦我删除了ui-bootstrap文件我的模态工作......我瞎了吗?或者它不是真的在github上的文档中说出你需要哪一个? -
现在我只需要弄清楚如何防止我的网址实际进入/登录,而不是只显示模态:)
更新2
好的,所以通过在服务中调用$ state.go('login')为我做这个.
小智 11
嗨,我很难解决类似的问题.但是,我能够解决它.这是你可能需要的.
app.config(function($stateProvider) {
$stateProvider.state("managerState", {
url: "/ManagerRecord",
controller: "myController",
templateUrl: 'index.html'
})
.state("employeeState", {
url: "empRecords",
parent: "managerState",
params: {
empId: 0
},
onEnter: [
"$modal",
function($modal) {
$modal.open({
controller: "EmpDetailsController",
controllerAs: "empDetails",
templateUrl: 'empDetails.html',
size: 'sm'
}).result.finally(function() {
$stateProvider.go('^');
});
}
]
});
});
Run Code Online (Sandbox Code Playgroud)
点击这里获取plunker.希望能帮助到你.
我正在做类似的事情,这是我的解决方案.
HTML代码
<a ui-sref="home.modal({path: 'login'})" class="btn btn-default" ng-click="openModal()">Login</a>
Run Code Online (Sandbox Code Playgroud)
状态配置
$stateProvider
// assuming we want to open the modal on home page
.state('home', {
url: '/',
templateUrl: '/views/index',
controller: 'HomeCtrl'
})
// create a nested state
.state('home.modal', {
url: ':path/'
});
Run Code Online (Sandbox Code Playgroud)
家庭控制器
//... other code
$scope.openModal = function(){
$modal.open({
templateUrl: 'path/to/page.html',
resolve: {
newPath: function(){
return 'home'
},
oldPath: function(){
return 'home.modal'
}
},
controller: 'ModalInstanceController'
});
};
//... other code
Run Code Online (Sandbox Code Playgroud)
最后,模态实例控制器.此控制器将模态事件(打开/关闭)与URL路径更改同步.
angular.module("app").controller('ModalInstanceController', function($scope, $modalInstance, $state, newPath, oldPath) {
$modalInstance.opened.then(function(){
$state.go(newPath);
});
$modalInstance.result.then(null,function(){
$state.go(oldPath);
});
$scope.$on('$stateChangeSuccess', function () {
if($state.current.name != newPath){
$modalInstance.dismiss('cancel')
}
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30299 次 |
| 最近记录: |