@angular-wave/angular.ts 0.0.28 → 0.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/angular-ts.esm.js +1 -1
- package/dist/angular-ts.umd.js +1 -1
- package/index.html +2 -2
- package/package.json +1 -1
- package/src/core/controller.js +3 -0
- package/src/directive/controller.js +0 -56
- package/src/directive/controller.md +46 -0
- package/src/router/common/trace.js +7 -7
- package/src/router/directives/state-directives.js +75 -75
- package/src/router/directives/view-directive.js +21 -21
- package/src/router/hooks/update-globals.js +1 -1
- package/src/router/index.js +12 -12
- package/src/router/injectables.js +11 -11
- package/src/router/resolve/resolve-context.js +1 -1
- package/src/router/router.js +8 -77
- package/src/router/services.js +5 -43
- package/src/router/state/state-builder.js +1 -0
- package/src/router/state/state-object.js +1 -1
- package/src/router/state/state-registry.js +56 -3
- package/src/router/state/state-service.js +16 -25
- package/src/router/state/target-state.js +1 -1
- package/src/router/state/views.js +5 -5
- package/src/router/state-filters.js +0 -2
- package/src/router/state-provider.js +0 -2
- package/src/router/template-factory.js +4 -4
- package/src/router/transition/transition-service.js +2 -3
- package/src/router/url/url-config.js +0 -2
- package/src/router/url/url-matcher-factory.js +0 -1
- package/src/router/url/url-matcher.js +0 -8
- package/src/router/url/url-router.js +4 -0
- package/src/router/url/url-service.js +6 -6
- package/src/router/view/view.js +67 -65
- package/src/services/browser.js +1 -5
- package/src/shared/common.js +1 -1
- package/test/core/pubsub.spec.js +73 -0
- package/test/module-test.html +5 -5
- package/test/original-test.html +3 -3
- package/test/router/services.spec.js +1 -1
- package/test/router/state-directives.spec.js +72 -80
- package/test/router/state-filter.spec.js +6 -4
- package/test/router/state.spec.js +15 -13
- package/test/router/template-factory.spec.js +4 -4
- package/test/router/url-matcher-factory.spec.js +2 -2
- package/test/router/view-directive.spec.js +165 -163
- package/test/router/view-hook.spec.js +2 -2
- package/test/router/view-scroll.spec.js +14 -14
- package/test/router/view.spec.js +2 -2
- package/types/router/core/common/coreservices.d.ts +2 -2
- package/types/router/core/common/trace.d.ts +7 -7
- package/types/router/core/globals.d.ts +2 -1
- package/types/router/core/interface.d.ts +3 -10
- package/types/router/core/params/interface.d.ts +3 -3
- package/types/router/core/resolve/resolveContext.d.ts +4 -4
- package/types/router/core/router.d.ts +5 -51
- package/types/router/core/state/interface.d.ts +12 -12
- package/types/router/core/state/stateObject.d.ts +1 -1
- package/types/router/core/state/stateQueueManager.d.ts +2 -2
- package/types/router/core/state/stateRegistry.d.ts +5 -4
- package/types/router/core/state/stateService.d.ts +13 -13
- package/types/router/core/state/targetState.d.ts +1 -1
- package/types/router/core/transition/interface.d.ts +2 -2
- package/types/router/core/transition/transition.d.ts +12 -12
- package/types/router/core/transition/transitionService.d.ts +5 -5
- package/types/router/core/url/interface.d.ts +3 -3
- package/types/router/core/url/urlConfig.d.ts +3 -3
- package/types/router/core/url/urlMatcherFactory.d.ts +3 -3
- package/types/router/core/url/urlRouter.d.ts +2 -2
- package/types/router/core/url/urlRule.d.ts +6 -6
- package/types/router/core/url/urlRules.d.ts +6 -6
- package/types/router/core/url/urlService.d.ts +8 -8
- package/types/router/core/view/interface.d.ts +3 -3
- package/types/router/core/view/view.d.ts +26 -26
- package/types/router/directives/viewDirective.d.ts +6 -6
- package/types/router/interface.d.ts +8 -8
- package/types/router/locationServices.d.ts +3 -3
- package/types/router/services.d.ts +1 -1
- package/types/router/stateProvider.d.ts +5 -5
- package/types/router/statebuilders/views.d.ts +1 -1
- package/types/router/templateFactory.d.ts +2 -2
- package/types/router/viewScroll.d.ts +2 -2
package/index.html
CHANGED
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
<script type="module" src="test/shared/hof.spec.js"></script>
|
|
97
97
|
<script type="module" src="test/shared/strings.spec.js"></script>
|
|
98
98
|
<script type="module" src="test/shared/utils.spec.js"></script>-->
|
|
99
|
-
<!-- <script type="module" src="test/core/pubsub.spec.js"></script
|
|
99
|
+
<!-- <script type="module" src="test/core/pubsub.spec.js"></script>-->
|
|
100
100
|
<script type="module" src="test/router/glob.spec.js"></script>
|
|
101
101
|
<script type="module" src="test/router/services.spec.js"></script>
|
|
102
102
|
<script type="module" src="test/router/state-directives.spec.js"></script>
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
<script type="module" src="test/router/view-directive.spec.js"></script>
|
|
108
108
|
<script type="module" src="test/router/view-hook.spec.js"></script>
|
|
109
109
|
<script type="module" src="test/router/view-scroll.spec.js"></script>
|
|
110
|
-
<script type="module" src="test/router/view.spec.js"></script>
|
|
110
|
+
<script type="module" src="test/router/view.spec.js"></script>
|
|
111
111
|
|
|
112
112
|
|
|
113
113
|
<!-- <script type="module" src="test/core/interval.spec.js"></script>
|
package/package.json
CHANGED
package/src/core/controller.js
CHANGED
|
@@ -98,7 +98,10 @@ export function $ControllerProvider() {
|
|
|
98
98
|
// param `ident` --- An optional label which overrides the label parsed from the controller
|
|
99
99
|
// expression, if any.
|
|
100
100
|
let instance;
|
|
101
|
+
|
|
102
|
+
/** @type { RegExpMatchArray | null} */
|
|
101
103
|
let match;
|
|
104
|
+
|
|
102
105
|
let constructor;
|
|
103
106
|
let identifier;
|
|
104
107
|
later = later === true;
|
|
@@ -1,59 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @ngdoc directive
|
|
3
|
-
* @name ngController
|
|
4
|
-
*
|
|
5
|
-
* @description
|
|
6
|
-
* The `ngController` directive attaches a controller class to the view. This is a key aspect of how angular
|
|
7
|
-
* supports the principles behind the Model-View-Controller design pattern.
|
|
8
|
-
*
|
|
9
|
-
* MVC components in angular:
|
|
10
|
-
*
|
|
11
|
-
* * Model — Models are the properties of a scope; scopes are attached to the DOM where scope properties
|
|
12
|
-
* are accessed through bindings.
|
|
13
|
-
* * View — The template (HTML with data bindings) that is rendered into the View.
|
|
14
|
-
* * Controller — The `ngController` directive specifies a Controller class; the class contains business
|
|
15
|
-
* logic behind the application to decorate the scope with functions and values
|
|
16
|
-
*
|
|
17
|
-
* Note that you can also attach controllers to the DOM by declaring it in a route definition
|
|
18
|
-
* via the {@link ngRoute.$route $route} service. A common mistake is to declare the controller
|
|
19
|
-
* again using `ng-controller` in the template itself. This will cause the controller to be attached
|
|
20
|
-
* and executed twice.
|
|
21
|
-
*
|
|
22
|
-
* @element ANY
|
|
23
|
-
* @scope
|
|
24
|
-
* @priority 500
|
|
25
|
-
* @param {String} ngController Name of a constructor function registered with the current
|
|
26
|
-
* {@link ng.$controllerProvider $controllerProvider} or an {@link guide/expression expression}
|
|
27
|
-
* that on the current scope evaluates to a constructor function.
|
|
28
|
-
*
|
|
29
|
-
* The controller instance can be published into a scope property by specifying
|
|
30
|
-
* `ng-controller="as propertyName"`.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* Here is a simple form for editing user contact information. Adding, removing, clearing, and
|
|
34
|
-
* greeting are methods declared on the controller (see source tab). These methods can
|
|
35
|
-
* easily be called from the AngularJS markup. Any changes to the data are automatically reflected
|
|
36
|
-
* in the View without the need for a manual update.
|
|
37
|
-
*
|
|
38
|
-
* Two different declaration styles are included below:
|
|
39
|
-
*
|
|
40
|
-
* * one binds methods and properties directly onto the controller using `this`:
|
|
41
|
-
* `ng-controller="SettingsController1 as settings"`
|
|
42
|
-
* * one injects `$scope` into the controller:
|
|
43
|
-
* `ng-controller="SettingsController2"`
|
|
44
|
-
*
|
|
45
|
-
* The second option is more common in the AngularJS community, and is generally used in boilerplates
|
|
46
|
-
* and in this guide. However, there are advantages to binding properties directly to the controller
|
|
47
|
-
* and avoiding scope.
|
|
48
|
-
*
|
|
49
|
-
* * Using `controller as` makes it obvious which controller you are accessing in the template when
|
|
50
|
-
* multiple controllers apply to an element.
|
|
51
|
-
* * If you are writing your controllers as classes you have easier access to the properties and
|
|
52
|
-
* methods, which will appear on the scope, from inside the controller code.
|
|
53
|
-
* * Since there is always a `.` in the bindings, you don't have to worry about prototypal
|
|
54
|
-
* inheritance masking primitives.
|
|
55
|
-
*
|
|
56
|
-
*/
|
|
57
1
|
export const ngControllerDirective = [
|
|
58
2
|
() => ({
|
|
59
3
|
restrict: "A",
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# ngController Directive
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
The `ngController` directive attaches a controller class to the view. This is a key aspect of how Angular supports the principles behind the Model-View-Controller design pattern.
|
|
6
|
+
|
|
7
|
+
### MVC components in Angular:
|
|
8
|
+
|
|
9
|
+
- **Model**: Models are the properties of a scope; scopes are attached to the DOM where scope properties are accessed through bindings.
|
|
10
|
+
- **View**: The template (HTML with data bindings) that is rendered into the View.
|
|
11
|
+
- **Controller**: The `ngController` directive specifies a Controller class; the class contains business logic behind the application to decorate the scope with functions and values.
|
|
12
|
+
|
|
13
|
+
Note that you can also attach controllers to the DOM by declaring it in a route definition via the [$route](https://docs.angularjs.org/api/ngRoute/service/$route) service. A common mistake is to declare the controller again using `ng-controller` in the template itself. This will cause the controller to be attached and executed twice.
|
|
14
|
+
|
|
15
|
+
## Element
|
|
16
|
+
|
|
17
|
+
`ANY`
|
|
18
|
+
|
|
19
|
+
## Scope
|
|
20
|
+
|
|
21
|
+
Yes
|
|
22
|
+
|
|
23
|
+
## Priority
|
|
24
|
+
|
|
25
|
+
500
|
|
26
|
+
|
|
27
|
+
## Parameter
|
|
28
|
+
|
|
29
|
+
- **ngController**: Name of a constructor function registered with the current [$controllerProvider](https://docs.angularjs.org/api/ng/provider/$controllerProvider) or an [expression](https://docs.angularjs.org/guide/expression) that on the current scope evaluates to a constructor function.
|
|
30
|
+
|
|
31
|
+
The controller instance can be published into a scope property by specifying `ng-controller="as propertyName"`.
|
|
32
|
+
|
|
33
|
+
## Example
|
|
34
|
+
|
|
35
|
+
Here is a simple form for editing user contact information. Adding, removing, clearing, and greeting are methods declared on the controller (see source tab). These methods can easily be called from the AngularJS markup. Any changes to the data are automatically reflected in the View without the need for a manual update.
|
|
36
|
+
|
|
37
|
+
Two different declaration styles are included below:
|
|
38
|
+
|
|
39
|
+
- One binds methods and properties directly onto the controller using `this`: `ng-controller="SettingsController1 as settings"`
|
|
40
|
+
- One injects `$scope` into the controller: `ng-controller="SettingsController2"`
|
|
41
|
+
|
|
42
|
+
The second option is more common in the AngularJS community and is generally used in boilerplates and in this guide. However, there are advantages to binding properties directly to the controller and avoiding scope.
|
|
43
|
+
|
|
44
|
+
- Using `controller as` makes it obvious which controller you are accessing in the template when multiple controllers apply to an element.
|
|
45
|
+
- If you are writing your controllers as classes you have easier access to the properties and methods, which will appear on the scope, from inside the controller code.
|
|
46
|
+
- Since there is always a `.` in the bindings, you don't have to worry about prototypal inheritance masking primitives.
|
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
maxLength,
|
|
41
41
|
padString,
|
|
42
42
|
} from "../../shared/strings";
|
|
43
|
-
function
|
|
43
|
+
function ngViewString(uiview) {
|
|
44
44
|
if (!uiview) return "ui-view (defunct)";
|
|
45
45
|
const state = uiview.creationContext
|
|
46
46
|
? uiview.creationContext.name || "(root)"
|
|
@@ -50,7 +50,7 @@ function uiViewString(uiview) {
|
|
|
50
50
|
const viewConfigString = (viewConfig) => {
|
|
51
51
|
const view = viewConfig.viewDecl;
|
|
52
52
|
const state = view.$context.name || "(root)";
|
|
53
|
-
return `[View#${viewConfig.$id} from '${state}' state]: target ui-view: '${view.$
|
|
53
|
+
return `[View#${viewConfig.$id} from '${state}' state]: target ui-view: '${view.$ngViewName}@${view.$ngViewContextAnchor}'`;
|
|
54
54
|
};
|
|
55
55
|
function normalizedCat(input) {
|
|
56
56
|
return isNumber(input) ? Category[input] : Category[Category[input]];
|
|
@@ -81,7 +81,7 @@ const _tid = parse("$id");
|
|
|
81
81
|
const _rid = parse("router.$id");
|
|
82
82
|
const transLbl = (trans) => `Transition #${_tid(trans)}-${_rid(trans)}`;
|
|
83
83
|
/**
|
|
84
|
-
* Prints
|
|
84
|
+
* Prints ng-router Transition trace information to the console.
|
|
85
85
|
*/
|
|
86
86
|
export class Trace {
|
|
87
87
|
constructor() {
|
|
@@ -178,7 +178,7 @@ export class Trace {
|
|
|
178
178
|
traceUIViewEvent(event, viewData, extra = "") {
|
|
179
179
|
if (!this.enabled(Category.UIVIEW)) return;
|
|
180
180
|
console.log(
|
|
181
|
-
`ui-view: ${padString(30, event)} ${
|
|
181
|
+
`ui-view: ${padString(30, event)} ${ngViewString(viewData)}${extra}`,
|
|
182
182
|
);
|
|
183
183
|
}
|
|
184
184
|
/** @internal called by ui-router code */
|
|
@@ -201,8 +201,8 @@ export class Trace {
|
|
|
201
201
|
const uivheader = "uiview component fqn";
|
|
202
202
|
const cfgheader = "view config state (view name)";
|
|
203
203
|
const mapping = pairs
|
|
204
|
-
.map(({
|
|
205
|
-
const uiv =
|
|
204
|
+
.map(({ ngView, viewConfig }) => {
|
|
205
|
+
const uiv = ngView && ngView.fqn;
|
|
206
206
|
const cfg =
|
|
207
207
|
viewConfig &&
|
|
208
208
|
`${viewConfig.viewDecl.$context.name}: (${viewConfig.viewDecl.$name})`;
|
|
@@ -219,7 +219,7 @@ export class Trace {
|
|
|
219
219
|
/** @internal called by ui-router code */
|
|
220
220
|
traceViewServiceUIViewEvent(event, viewData) {
|
|
221
221
|
if (!this.enabled(Category.VIEWCONFIG)) return;
|
|
222
|
-
console.log(`VIEWCONFIG: ${event} ${
|
|
222
|
+
console.log(`VIEWCONFIG: ${event} ${ngViewString(viewData)}`);
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* # Angular 1 Directives
|
|
3
3
|
*
|
|
4
|
-
* These are the directives included in
|
|
4
|
+
* These are the directives included in ng-router for Angular 1.
|
|
5
5
|
* These directives are used in templates to create viewports and link/navigate to states.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
@@ -29,19 +29,19 @@ function parseStateRef(ref) {
|
|
|
29
29
|
}
|
|
30
30
|
/** @hidden */
|
|
31
31
|
function stateContext(el) {
|
|
32
|
-
const $
|
|
33
|
-
const path = parse("$cfg.path")($
|
|
32
|
+
const $ngView = el.parent().inheritedData("$ngView");
|
|
33
|
+
const path = parse("$cfg.path")($ngView);
|
|
34
34
|
return path ? tail(path).state.name : undefined;
|
|
35
35
|
}
|
|
36
36
|
/** @hidden */
|
|
37
37
|
function processedDef($state, $element, def) {
|
|
38
|
-
const
|
|
39
|
-
const
|
|
38
|
+
const ngState = def.ngState || $state.current.name;
|
|
39
|
+
const ngStateOpts = Object.assign(
|
|
40
40
|
defaultOpts($element, $state),
|
|
41
|
-
def.
|
|
41
|
+
def.ngStateOpts || {},
|
|
42
42
|
);
|
|
43
|
-
const href = $state.href(
|
|
44
|
-
return {
|
|
43
|
+
const href = $state.href(ngState, def.ngStateParams, ngStateOpts);
|
|
44
|
+
return { ngState, ngStateParams: def.ngStateParams, ngStateOpts, href };
|
|
45
45
|
}
|
|
46
46
|
/** @hidden */
|
|
47
47
|
function getTypeInfo(el) {
|
|
@@ -73,7 +73,7 @@ function clickHook(el, $state, $timeout, type, getDef) {
|
|
|
73
73
|
// HACK: This is to allow ng-clicks to be processed before the transition is initiated:
|
|
74
74
|
const transition = $timeout(function () {
|
|
75
75
|
if (!el.attr("disabled")) {
|
|
76
|
-
$state.go(target.
|
|
76
|
+
$state.go(target.ngState, target.ngStateParams, target.ngStateOpts);
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
79
|
e.preventDefault();
|
|
@@ -98,10 +98,10 @@ function defaultOpts(el, $state) {
|
|
|
98
98
|
};
|
|
99
99
|
}
|
|
100
100
|
/** @hidden */
|
|
101
|
-
function bindEvents(element, scope, hookFn,
|
|
101
|
+
function bindEvents(element, scope, hookFn, ngStateOpts) {
|
|
102
102
|
let events;
|
|
103
|
-
if (
|
|
104
|
-
events =
|
|
103
|
+
if (ngStateOpts) {
|
|
104
|
+
events = ngStateOpts.events;
|
|
105
105
|
}
|
|
106
106
|
if (!Array.isArray(events)) {
|
|
107
107
|
events = ["click"];
|
|
@@ -196,7 +196,7 @@ function bindEvents(element, scope, hookFn, uiStateOpts) {
|
|
|
196
196
|
* ```
|
|
197
197
|
*
|
|
198
198
|
* ### Highlighting the active link
|
|
199
|
-
* This directive can be used in conjunction with [[
|
|
199
|
+
* This directive can be used in conjunction with [[ngSrefActive]] to highlight the active link.
|
|
200
200
|
*
|
|
201
201
|
* ### Examples
|
|
202
202
|
* If you have the following template:
|
|
@@ -248,34 +248,34 @@ function bindEvents(element, scope, hookFn, uiStateOpts) {
|
|
|
248
248
|
* - A middle-click, right-click, or ctrl-click is handled (natively) by the browser to open the href in a new window, for example.
|
|
249
249
|
*
|
|
250
250
|
* - Unlike the parameter values expression, the state name is not `$watch`ed (for performance reasons).
|
|
251
|
-
* If you need to dynamically update the state being linked to, use the fully dynamic [[
|
|
251
|
+
* If you need to dynamically update the state being linked to, use the fully dynamic [[ngState]] directive.
|
|
252
252
|
*/
|
|
253
|
-
export let
|
|
253
|
+
export let ngSrefDirective = [
|
|
254
254
|
"$router",
|
|
255
255
|
"$timeout",
|
|
256
256
|
function $StateRefDirective($router, $timeout) {
|
|
257
257
|
const $state = $router.stateService;
|
|
258
258
|
return {
|
|
259
259
|
restrict: "A",
|
|
260
|
-
require: ["?^
|
|
261
|
-
link: (scope, element, attrs,
|
|
260
|
+
require: ["?^ngSrefActive", "?^ngSrefActiveEq"],
|
|
261
|
+
link: (scope, element, attrs, ngSrefActive) => {
|
|
262
262
|
const type = getTypeInfo(element);
|
|
263
|
-
const active =
|
|
263
|
+
const active = ngSrefActive[1] || ngSrefActive[0];
|
|
264
264
|
let unlinkInfoFn = null;
|
|
265
265
|
const rawDef = {};
|
|
266
266
|
const getDef = () => processedDef($state, element, rawDef);
|
|
267
|
-
const ref = parseStateRef(attrs.
|
|
268
|
-
rawDef.
|
|
269
|
-
rawDef.
|
|
270
|
-
? scope.$eval(attrs.
|
|
267
|
+
const ref = parseStateRef(attrs.ngSref);
|
|
268
|
+
rawDef.ngState = ref.state;
|
|
269
|
+
rawDef.ngStateOpts = attrs.ngSrefOpts
|
|
270
|
+
? scope.$eval(attrs.ngSrefOpts)
|
|
271
271
|
: {};
|
|
272
272
|
function update() {
|
|
273
273
|
const def = getDef();
|
|
274
274
|
if (unlinkInfoFn) unlinkInfoFn();
|
|
275
275
|
if (active)
|
|
276
276
|
unlinkInfoFn = active.$$addStateInfo(
|
|
277
|
-
def.
|
|
278
|
-
def.
|
|
277
|
+
def.ngState,
|
|
278
|
+
def.ngStateParams,
|
|
279
279
|
);
|
|
280
280
|
if (def.href != null) attrs.$set(type.attr, def.href);
|
|
281
281
|
}
|
|
@@ -283,123 +283,123 @@ export let uiSrefDirective = [
|
|
|
283
283
|
scope.$watch(
|
|
284
284
|
ref.paramExpr,
|
|
285
285
|
function (val) {
|
|
286
|
-
rawDef.
|
|
286
|
+
rawDef.ngStateParams = Object.assign({}, val);
|
|
287
287
|
update();
|
|
288
288
|
},
|
|
289
289
|
true,
|
|
290
290
|
);
|
|
291
|
-
rawDef.
|
|
291
|
+
rawDef.ngStateParams = Object.assign({}, scope.$eval(ref.paramExpr));
|
|
292
292
|
}
|
|
293
293
|
update();
|
|
294
294
|
scope.$on("$destroy", $router.stateRegistry.onStatesChanged(update));
|
|
295
295
|
scope.$on("$destroy", $router.transitionService.onSuccess({}, update));
|
|
296
296
|
if (!type.clickable) return;
|
|
297
297
|
const hookFn = clickHook(element, $state, $timeout, type, getDef);
|
|
298
|
-
bindEvents(element, scope, hookFn, rawDef.
|
|
298
|
+
bindEvents(element, scope, hookFn, rawDef.ngStateOpts);
|
|
299
299
|
},
|
|
300
300
|
};
|
|
301
301
|
},
|
|
302
302
|
];
|
|
303
303
|
/**
|
|
304
|
-
* `
|
|
304
|
+
* `ng-state`: A fully dynamic directive for linking to a state
|
|
305
305
|
*
|
|
306
306
|
* A directive which links to a state (and optionally, parameters).
|
|
307
307
|
* When clicked, this directive activates the linked state with the supplied parameter values.
|
|
308
308
|
*
|
|
309
|
-
* **This directive is very similar to [[
|
|
309
|
+
* **This directive is very similar to [[ngSref]], but it `$observe`s and `$watch`es/evaluates all its inputs.**
|
|
310
310
|
*
|
|
311
311
|
* A directive which links to a state (and optionally, parameters).
|
|
312
312
|
* When clicked, this directive activates the linked state with the supplied parameter values.
|
|
313
313
|
*
|
|
314
314
|
* ### Linked State
|
|
315
|
-
* The attribute value of `
|
|
315
|
+
* The attribute value of `ng-state` is an expression which is `$watch`ed and evaluated as the state to link to.
|
|
316
316
|
* **This is in contrast with `ui-sref`, which takes a state name as a string literal.**
|
|
317
317
|
*
|
|
318
318
|
* #### Example:
|
|
319
319
|
* Create a list of links.
|
|
320
320
|
* ```html
|
|
321
321
|
* <li ng-repeat="link in navlinks">
|
|
322
|
-
* <a
|
|
322
|
+
* <a ng-state="link.state">{{ link.displayName }}</a>
|
|
323
323
|
* </li>
|
|
324
324
|
* ```
|
|
325
325
|
*
|
|
326
326
|
* ### Relative Links
|
|
327
|
-
* If the expression evaluates to a relative path, it is processed like [[
|
|
327
|
+
* If the expression evaluates to a relative path, it is processed like [[ngSref]].
|
|
328
328
|
* You just need to be aware that the path is relative to the state that *created* the link.
|
|
329
|
-
* This allows a state to create relative `
|
|
329
|
+
* This allows a state to create relative `ng-state` which always targets the same destination.
|
|
330
330
|
*
|
|
331
331
|
* ### hrefs
|
|
332
332
|
* If the linked state has a URL, the directive will automatically generate and
|
|
333
333
|
* update the `href` attribute (using the [[StateService.href]] method).
|
|
334
334
|
*
|
|
335
335
|
* ### Parameter Values
|
|
336
|
-
* In addition to the state name expression, a `
|
|
337
|
-
* Param values should be provided using the `
|
|
338
|
-
* The `
|
|
336
|
+
* In addition to the state name expression, a `ng-state` can include parameter values which are applied when activating the state.
|
|
337
|
+
* Param values should be provided using the `ng-state-params` attribute.
|
|
338
|
+
* The `ng-state-params` attribute value is `$watch`ed and evaluated as an expression.
|
|
339
339
|
*
|
|
340
340
|
* #### Example:
|
|
341
341
|
* This example renders a list of links with param values.
|
|
342
342
|
* The state's `userId` parameter value comes from each user's `user.id` property.
|
|
343
343
|
* ```html
|
|
344
344
|
* <li ng-repeat="link in navlinks">
|
|
345
|
-
* <a
|
|
345
|
+
* <a ng-state="link.state" ng-state-params="link.params">{{ link.displayName }}</a>
|
|
346
346
|
* </li>
|
|
347
347
|
* ```
|
|
348
348
|
*
|
|
349
349
|
* ### Transition Options
|
|
350
|
-
* You can specify [[TransitionOptions]] to pass to [[StateService.go]] by using the `
|
|
350
|
+
* You can specify [[TransitionOptions]] to pass to [[StateService.go]] by using the `ng-state-opts` attribute.
|
|
351
351
|
* Options are restricted to `location`, `inherit`, and `reload`.
|
|
352
|
-
* The value of the `
|
|
352
|
+
* The value of the `ng-state-opts` is `$watch`ed and evaluated as an expression.
|
|
353
353
|
*
|
|
354
354
|
* #### Example:
|
|
355
355
|
* ```html
|
|
356
|
-
* <a
|
|
356
|
+
* <a ng-state="returnto.state" ng-state-opts="{ reload: true }">Home</a>
|
|
357
357
|
* ```
|
|
358
358
|
*
|
|
359
359
|
* ### Other DOM Events
|
|
360
360
|
*
|
|
361
361
|
* You can also customize which DOM events to respond to (instead of `click`) by
|
|
362
|
-
* providing an `events` array in the `
|
|
362
|
+
* providing an `events` array in the `ng-state-opts` attribute.
|
|
363
363
|
*
|
|
364
364
|
* #### Example:
|
|
365
365
|
* ```html
|
|
366
|
-
* <input type="text"
|
|
366
|
+
* <input type="text" ng-state="contacts" ng-state-opts="{ events: ['change', 'blur'] }">
|
|
367
367
|
* ```
|
|
368
368
|
*
|
|
369
369
|
* ### Highlighting the active link
|
|
370
|
-
* This directive can be used in conjunction with [[
|
|
370
|
+
* This directive can be used in conjunction with [[ngSrefActive]] to highlight the active link.
|
|
371
371
|
*
|
|
372
372
|
* ### Notes
|
|
373
373
|
*
|
|
374
|
-
* - You can use `ui-params` to change **only the parameter values** by omitting the state name and supplying only `
|
|
375
|
-
* However, it might be simpler to use [[
|
|
374
|
+
* - You can use `ui-params` to change **only the parameter values** by omitting the state name and supplying only `ng-state-params`.
|
|
375
|
+
* However, it might be simpler to use [[ngSref]] parameter-only links.
|
|
376
376
|
*
|
|
377
377
|
* #### Example:
|
|
378
378
|
* Sets the `lang` parameter to `en` and remains on the same state.
|
|
379
379
|
*
|
|
380
380
|
* ```html
|
|
381
|
-
* <a
|
|
381
|
+
* <a ng-state="" ng-state-params="{ lang: 'en' }">English</a>
|
|
382
382
|
* ```
|
|
383
383
|
*
|
|
384
384
|
* - A middle-click, right-click, or ctrl-click is handled (natively) by the browser to open the href in a new window, for example.
|
|
385
385
|
* ```
|
|
386
386
|
*/
|
|
387
|
-
export let
|
|
387
|
+
export let ngStateDirective = [
|
|
388
388
|
"$router",
|
|
389
389
|
"$timeout",
|
|
390
390
|
function $StateRefDynamicDirective($router, $timeout) {
|
|
391
391
|
const $state = $router.stateService;
|
|
392
392
|
return {
|
|
393
393
|
restrict: "A",
|
|
394
|
-
require: ["?^
|
|
395
|
-
link: function (scope, element, attrs,
|
|
394
|
+
require: ["?^ngSrefActive", "?^ngSrefActiveEq"],
|
|
395
|
+
link: function (scope, element, attrs, ngSrefActive) {
|
|
396
396
|
const type = getTypeInfo(element);
|
|
397
|
-
const active =
|
|
397
|
+
const active = ngSrefActive[1] || ngSrefActive[0];
|
|
398
398
|
let unlinkInfoFn = null;
|
|
399
399
|
let hookFn;
|
|
400
400
|
const rawDef = {};
|
|
401
401
|
const getDef = () => processedDef($state, element, rawDef);
|
|
402
|
-
const inputAttrs = ["
|
|
402
|
+
const inputAttrs = ["ngState", "ngStateParams", "ngStateOpts"];
|
|
403
403
|
const watchDeregFns = inputAttrs.reduce(
|
|
404
404
|
(acc, attr) => ((acc[attr] = () => {}), acc),
|
|
405
405
|
{},
|
|
@@ -409,8 +409,8 @@ export let uiStateDirective = [
|
|
|
409
409
|
if (unlinkInfoFn) unlinkInfoFn();
|
|
410
410
|
if (active)
|
|
411
411
|
unlinkInfoFn = active.$$addStateInfo(
|
|
412
|
-
def.
|
|
413
|
-
def.
|
|
412
|
+
def.ngState,
|
|
413
|
+
def.ngStateParams,
|
|
414
414
|
);
|
|
415
415
|
if (def.href != null) attrs.$set(type.attr, def.href);
|
|
416
416
|
}
|
|
@@ -433,7 +433,7 @@ export let uiStateDirective = [
|
|
|
433
433
|
scope.$on("$destroy", $router.transitionService.onSuccess({}, update));
|
|
434
434
|
if (!type.clickable) return;
|
|
435
435
|
hookFn = clickHook(element, $state, $timeout, type, getDef);
|
|
436
|
-
bindEvents(element, scope, hookFn, rawDef.
|
|
436
|
+
bindEvents(element, scope, hookFn, rawDef.ngStateOpts);
|
|
437
437
|
},
|
|
438
438
|
};
|
|
439
439
|
},
|
|
@@ -441,26 +441,26 @@ export let uiStateDirective = [
|
|
|
441
441
|
/**
|
|
442
442
|
* `ui-sref-active` and `ui-sref-active-eq`: A directive that adds a CSS class when a `ui-sref` is active
|
|
443
443
|
*
|
|
444
|
-
* A directive working alongside [[
|
|
444
|
+
* A directive working alongside [[ngSref]] and [[ngState]] to add classes to an element when the
|
|
445
445
|
* related directive's state is active (and remove them when it is inactive).
|
|
446
446
|
*
|
|
447
447
|
* The primary use-case is to highlight the active link in navigation menus,
|
|
448
448
|
* distinguishing it from the inactive menu items.
|
|
449
449
|
*
|
|
450
|
-
* ### Linking to a `ui-sref` or `
|
|
451
|
-
* `ui-sref-active` can live on the same element as `ui-sref`/`
|
|
452
|
-
* If a `ui-sref-active` is a parent to more than one `ui-sref`/`
|
|
450
|
+
* ### Linking to a `ui-sref` or `ng-state`
|
|
451
|
+
* `ui-sref-active` can live on the same element as `ui-sref`/`ng-state`, or it can be on a parent element.
|
|
452
|
+
* If a `ui-sref-active` is a parent to more than one `ui-sref`/`ng-state`, it will apply the CSS class when **any of the links are active**.
|
|
453
453
|
*
|
|
454
454
|
* ### Matching
|
|
455
455
|
*
|
|
456
|
-
* The `ui-sref-active` directive applies the CSS class when the `ui-sref`/`
|
|
456
|
+
* The `ui-sref-active` directive applies the CSS class when the `ui-sref`/`ng-state`'s target state **or any child state is active**.
|
|
457
457
|
* This is a "fuzzy match" which uses [[StateService.includes]].
|
|
458
458
|
*
|
|
459
|
-
* The `ui-sref-active-eq` directive applies the CSS class when the `ui-sref`/`
|
|
459
|
+
* The `ui-sref-active-eq` directive applies the CSS class when the `ui-sref`/`ng-state`'s target state is directly active (not when child states are active).
|
|
460
460
|
* This is an "exact match" which uses [[StateService.is]].
|
|
461
461
|
*
|
|
462
462
|
* ### Parameter values
|
|
463
|
-
* If the `ui-sref`/`
|
|
463
|
+
* If the `ui-sref`/`ng-state` includes parameter values, the current parameter values must match the link's values for the link to be highlighted.
|
|
464
464
|
* This allows a list of links to the same state with different parameters to be rendered, and the correct one highlighted.
|
|
465
465
|
*
|
|
466
466
|
* #### Example:
|
|
@@ -530,7 +530,7 @@ export let uiStateDirective = [
|
|
|
530
530
|
*
|
|
531
531
|
* - Multiple classes may be specified in a space-separated format: `ui-sref-active='class1 class2 class3'`
|
|
532
532
|
*/
|
|
533
|
-
export let
|
|
533
|
+
export let ngSrefActiveDirective = [
|
|
534
534
|
"$state",
|
|
535
535
|
"$stateParams",
|
|
536
536
|
"$interpolate",
|
|
@@ -550,32 +550,32 @@ export let uiSrefActiveDirective = [
|
|
|
550
550
|
function ($scope, $element, $attrs) {
|
|
551
551
|
let states = [];
|
|
552
552
|
let activeEqClass;
|
|
553
|
-
let
|
|
553
|
+
let ngSrefActive;
|
|
554
554
|
// There probably isn't much point in $observing this
|
|
555
|
-
//
|
|
555
|
+
// ngSrefActive and ngSrefActiveEq share the same directive object with some
|
|
556
556
|
// slight difference in logic routing
|
|
557
557
|
activeEqClass = $interpolate(
|
|
558
|
-
$attrs.
|
|
558
|
+
$attrs.ngSrefActiveEq || "",
|
|
559
559
|
false,
|
|
560
560
|
)($scope);
|
|
561
561
|
try {
|
|
562
|
-
|
|
562
|
+
ngSrefActive = $scope.$eval($attrs.ngSrefActive);
|
|
563
563
|
} catch (e) {
|
|
564
|
-
// Do nothing.
|
|
564
|
+
// Do nothing. ngSrefActive is not a valid expression.
|
|
565
565
|
// Fall back to using $interpolate below
|
|
566
566
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
$interpolate($attrs.
|
|
570
|
-
setStatesFromDefinitionObject(
|
|
571
|
-
// Allow
|
|
567
|
+
ngSrefActive =
|
|
568
|
+
ngSrefActive ||
|
|
569
|
+
$interpolate($attrs.ngSrefActive || "", false)($scope);
|
|
570
|
+
setStatesFromDefinitionObject(ngSrefActive);
|
|
571
|
+
// Allow ngSref to communicate with ngSrefActive[Equals]
|
|
572
572
|
this.$$addStateInfo = function (newState, newParams) {
|
|
573
573
|
// we already got an explicit state provided by ui-sref-active, so we
|
|
574
574
|
// shadow the one that comes from ui-sref
|
|
575
|
-
if (isObject(
|
|
575
|
+
if (isObject(ngSrefActive) && states.length > 0) {
|
|
576
576
|
return;
|
|
577
577
|
}
|
|
578
|
-
const deregister = addState(newState, newParams,
|
|
578
|
+
const deregister = addState(newState, newParams, ngSrefActive);
|
|
579
579
|
update();
|
|
580
580
|
return deregister;
|
|
581
581
|
};
|
|
@@ -604,7 +604,7 @@ export let uiSrefActiveDirective = [
|
|
|
604
604
|
};
|
|
605
605
|
}
|
|
606
606
|
function handleStatesChanged() {
|
|
607
|
-
setStatesFromDefinitionObject(
|
|
607
|
+
setStatesFromDefinitionObject(ngSrefActive);
|
|
608
608
|
}
|
|
609
609
|
function setStatesFromDefinitionObject(statesDefinition) {
|
|
610
610
|
if (isObject(statesDefinition)) {
|