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';
|
|
|
|
import {BINDING_INDEX, HEADER_OFFSET, RENDERER, TVIEW} from '../interfaces/view';
|
|
|
|
import {appendChild, createTextNode} from '../node_manipulation';
|
2019-05-14 21:47:11 -07:00
|
|
|
import {getLView, 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';
|
|
|
|
import {createNodeAtIndex} from './shared';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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++;
|
|
|
|
const textNative = createTextNode(value, lView[RENDERER]);
|
|
|
|
const tNode = createNodeAtIndex(index, TNodeType.Element, textNative, null, null);
|
|
|
|
|
|
|
|
// 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 index Index of the node in the data array.
|
|
|
|
* @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-17 18:49:21 -07:00
|
|
|
export function ɵɵtextBinding<T>(index: number, value: T | NO_CHANGE): void {
|
2019-04-01 15:36:43 -07:00
|
|
|
if (value !== NO_CHANGE) {
|
|
|
|
const lView = getLView();
|
|
|
|
ngDevMode && assertDataInRange(lView, index + HEADER_OFFSET);
|
|
|
|
const element = getNativeByIndex(index, lView) as any as RText;
|
|
|
|
ngDevMode && assertDefined(element, 'native element should exist');
|
|
|
|
ngDevMode && ngDevMode.rendererSetText++;
|
|
|
|
const renderer = lView[RENDERER];
|
|
|
|
isProceduralRenderer(renderer) ? renderer.setValue(element, renderStringify(value)) :
|
|
|
|
element.textContent = renderStringify(value);
|
|
|
|
}
|
|
|
|
}
|