2019-04-01 15:36:43 -07:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
import {assertDataInRange, assertDefined, assertEqual} from '../../util/assert';
|
|
|
|
import {TNodeType} from '../interfaces/node';
|
|
|
|
import {RText, isProceduralRenderer} from '../interfaces/renderer';
|
2019-05-31 14:41:07 -07:00
|
|
|
import {BINDING_INDEX, HEADER_OFFSET, LView, RENDERER, TVIEW, T_HOST} from '../interfaces/view';
|
2019-04-01 15:36:43 -07:00
|
|
|
import {appendChild, createTextNode} from '../node_manipulation';
|
2019-05-31 14:41:07 -07:00
|
|
|
import {getLView, getSelectedIndex, setIsNotParent} from '../state';
|
2019-04-01 15:36:43 -07:00
|
|
|
import {NO_CHANGE} from '../tokens';
|
|
|
|
import {renderStringify} from '../util/misc_utils';
|
|
|
|
import {getNativeByIndex} from '../util/view_utils';
|
2019-05-31 14:41:07 -07:00
|
|
|
|
2019-06-18 17:58:15 +02:00
|
|
|
import {bind} from './property';
|
2019-05-31 14:41:07 -07:00
|
|
|
import {getOrCreateTNode, textBindingInternal} from './shared';
|
|
|
|
|
|
|
|
|
2019-04-01 15:36:43 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create static text node
|
|
|
|
*
|
|
|
|
* @param index Index of the node in the data array
|
|
|
|
* @param value Value to write. This value will be stringified.
|
2019-04-04 11:41:52 -07:00
|
|
|
*
|
2019-04-10 13:45:26 -07:00
|
|
|
* @codeGenApi
|
2019-04-01 15:36:43 -07:00
|
|
|
*/
|
2019-05-17 18:49:21 -07:00
|
|
|
export function ɵɵtext(index: number, value?: any): void {
|
2019-04-01 15:36:43 -07:00
|
|
|
const lView = getLView();
|
|
|
|
ngDevMode && assertEqual(
|
|
|
|
lView[BINDING_INDEX], lView[TVIEW].bindingStartIndex,
|
|
|
|
'text nodes should be created before any bindings');
|
|
|
|
ngDevMode && ngDevMode.rendererCreateTextNode++;
|
2019-05-15 20:59:55 -07:00
|
|
|
ngDevMode && assertDataInRange(lView, index + HEADER_OFFSET);
|
|
|
|
const textNative = lView[index + HEADER_OFFSET] = createTextNode(value, lView[RENDERER]);
|
2019-05-31 14:41:07 -07:00
|
|
|
ngDevMode && ngDevMode.rendererSetText++;
|
2019-05-15 22:51:40 -07:00
|
|
|
const tNode = getOrCreateTNode(lView[TVIEW], lView[T_HOST], index, TNodeType.Element, null, null);
|
2019-04-01 15:36:43 -07:00
|
|
|
|
|
|
|
// Text nodes are self closing.
|
2019-05-14 21:47:11 -07:00
|
|
|
setIsNotParent();
|
2019-04-01 15:36:43 -07:00
|
|
|
appendChild(textNative, tNode, lView);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create text node with binding
|
|
|
|
* Bindings should be handled externally with the proper interpolation(1-8) method
|
|
|
|
*
|
|
|
|
* @param value Stringified value to write.
|
2019-04-04 11:41:52 -07:00
|
|
|
*
|
2019-04-10 13:45:26 -07:00
|
|
|
* @codeGenApi
|
2019-04-01 15:36:43 -07:00
|
|
|
*/
|
2019-05-31 14:41:07 -07:00
|
|
|
export function ɵɵtextBinding<T>(value: T | NO_CHANGE): void {
|
|
|
|
const lView = getLView();
|
|
|
|
const index = getSelectedIndex();
|
2019-06-18 17:58:15 +02:00
|
|
|
const bound = bind(lView, value);
|
2019-05-31 14:41:07 -07:00
|
|
|
if (bound !== NO_CHANGE) {
|
|
|
|
textBindingInternal(lView, index, renderStringify(bound));
|
2019-04-01 15:36:43 -07:00
|
|
|
}
|
|
|
|
}
|