angular-ui-router

angularjs controller instantiation, ui-router

北战南征 提交于 2020-01-02 22:13:44
问题 When do controllers get instantiated? Is it the first time you visit that state? also, What happens when you revisit the state, does a new controller get instantiated again? Assume that I have two states, A and B, and I put an alert statement at the top of state B. I noticed that if go from state A to B state B's alert statement sets off which tells me that the controller got instantiated. But suppose I go from state A to B to C and back to B, the alert statement does NOT go off. However, if

How to get $stateParams in parent view?

可紊 提交于 2020-01-02 21:18:22
问题 I want to make tabs with tab-content. tab-content has it's own view. Here is code sample (function () { angular .module('infirma.konfiguracja', ['ui.router']) .config(routeConfig) ; routeConfig.$inject = ['$stateProvider']; function routeConfig($stateProvider) { $stateProvider .state('app.konfiguracja', { url: 'konfiguracja/', views: { 'page@app': { templateUrl: 'app/konfiguracja/lista.html', controller: 'konfiguracjaListaCtrl', controllerAs: 'vm' } }, ncyBreadcrumb: {label: "Ustawienia

Nested parameterized routes with ui-router in AngularJS

不想你离开。 提交于 2020-01-02 09:56:42
问题 I believe I'm on the right track with these terms, "nested parameterized routes", but haven't found what I'm looking for yet. My objective is to create intuitive routes for my API, something like the following example: /api/v1/project/list /api/v1/project/1/item/list /api/v1/project/1/item/1/edit /api/v1/project/2/item/3/delete It's relatively easy and clear how to setup project states, but not the item states within each project. { state: 'project' config: { url:'/project' } }, { state:

Angular UI Router - Dynamic states get double slashes when navigated to with ui-sref

孤人 提交于 2020-01-02 08:21:55
问题 I'm creating a CMS system so I want the states to be dynamically created. Since you can't make http requests within the config phase I decided to add my routes in the .run() function as described here: http://blog.brunoscopelliti.com/how-to-defer-route-definition-in-an-angularjs-web-app Now when I display a list of links in my navigation partial using the ui-sref directive the url that is appended has 2 forward slashes instead of one. The controller and everything is called accordingly but I

angular 1.5 component, ui-router resolve, $onChanges lifecycle hook

醉酒当歌 提交于 2020-01-02 06:29:30
问题 In the following example (plunker), a ui-router state routes to an app component that has a data object and a replace method that replaces this object with a new one using the given value. In its template, it has: an editor component which triggers the replace method through a callback binding ('&') a display component which receives the data object through a 1-way binding ('<'), makes a local copy when the $onChanges lifecycle hook is triggered, and displays the contents of the object

Why $state.go doesn't work when destination state or it's parent resolves with promise

我们两清 提交于 2020-01-02 04:55:12
问题 I tried to load some data on parent state with resolve and to redirect user to default state when the app runs like so: app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) { $stateProvider.state('home', { url: '/', template: '<div><a ui-sref="home">Start App</a> <a ui-sref="home.main">Home</a> <a ui-sref="home.other">Other state</a><div ui-view>Loading...</div></div>', resolve: { user: ['$timeout', '$q', function($timeout, $q) { var deferred = $q

AngularJS reinitialize controller

百般思念 提交于 2020-01-02 04:15:13
问题 I have got a controller named newGroupCtrl whose definition is like : .state('new_group', { url: '/new_group', templateUrl: 'templates/new_group.html', controller: 'newGroupCtrl' }) .controller('newGroupCtrl', function ($scope, $rootScope,$ionicHistory,$window) { $rootScope.roomId = $scope.getRoom(); $scope.getRoom = function () { var date = new Date; var minutes = date.getMinutes(); var hour = date.getHours(); return 'room_' + hour + '' + minutes; }; } I reach this contoller from previous

Angular UI Router - allow ANY query string parameter

泪湿孤枕 提交于 2020-01-02 02:44:27
问题 I am using the Angular UI Router and this works well in most situations. However, I have a situation where I don't know the names of the query string parameters ahead of time. So normally with UI router you would define a route something like this: $stateProvider.state('test', { url: '/test?testQueryStringParam', templateUrl: 'Test.html', controller: 'TestController' }); Then in my controller I can access the testQueryStringParam using $stateParams. However, with UI router you can't access

How can I clear all the AngularJS $scope and $rootScope values within a single function?

狂风中的少年 提交于 2020-01-02 01:12:09
问题 I need to clear all the $scope values while performing some operations. For eg: If I Click a "Signout" button to redirect to "signin" page, then all the $scope or $rootScope values in the session should be cleared. How can I achieve this? 回答1: You can do the following: $rootScope = $rootScope.$new(true); $scope = $scope.$new(true); The function $new is creating a new scope inheriting the variables from the parent. true prevents the inheritance. But this is not the correct approach, because if

testing ui-router stateprovider 'resolve:' values

◇◆丶佛笑我妖孽 提交于 2020-01-01 07:18:51
问题 I'm using jasmine+karma to run the following code... and get the following error: Expected { then : Function, catch : Function, finally : Function } to equal 123. Can someone help me understand why I don't get a resolved value for my promise. thanks 'use strict'; angular .module('example', ['ui.router']) .config(function($stateProvider) { $stateProvider .state('stateOne', { url: '/stateOne', resolve: {cb: function($q) { var deferred = $q.defer(); deferred.resolve(123); return deferred.promise