docs/vendor.js
function getOrCreateInjectable(di, token, flags) {
    if (flags === void 0) { flags = 0 /* Default */; }
    var bloomHash = bloomHashBit(token);
    // If the token has a bloom hash, then it is a directive that is public to the injection system
    // (diPublic). If there is no hash, fall back to the module injector.
    if (bloomHash === null) {
        var moduleInjector = getPreviousOrParentNode().view[INJECTOR$1];
        var formerInjector = setCurrentInjector(moduleInjector);
        try {
            return inject(token, flags);
        }
        finally {
            setCurrentInjector(formerInjector);
        }
    }
    else {
        var injector = di;
        while (injector) {
            // Get the closest potential matching injector (upwards in the injector tree) that
            // *potentially* has the token.
            injector = bloomFindPossibleInjector(injector, bloomHash, flags);
            // If no injector is found, we *know* that there is no ancestor injector that contains the
            // token, so we abort.
            if (!injector) {
                break;
            }
            // At this point, we have an injector which *may* contain the token, so we step through the
            // directives associated with the injector's corresponding node to get the directive instance.
            var node = injector.node;
            var nodeFlags = node.tNode.flags;
            var count = nodeFlags & 4095 /* DirectiveCountMask */;
            if (count !== 0) {
                var start = nodeFlags >> 14 /* DirectiveStartingIndexShift */;
                var end = start + count;
                var defs = node.view[TVIEW].directives;
                for (var i = start; i < end; i++) {
                    // Get the definition for the directive at this index and, if it is injectable (diPublic),
                    // and matches the given token, return the directive instance.
                    var directiveDef = defs[i];
                    if (directiveDef.type === token && directiveDef.diPublic) {
                        return node.view[DIRECTIVES][i];
                    }
                }
            }
            // If we *didn't* find the directive for the token and we are searching the current node's
            // injector, it's possible the directive is on this node and hasn't been created yet.
            var instance = void 0;
            if (injector === di && (instance = searchMatchesQueuedForCreation(node, token))) {
                return instance;
            }
            // The def wasn't found anywhere on this node, so it was a false positive.
            // If flags permit, traverse up the tree and continue searching.
            if (flags & 2 /* Self */ || flags & 1 /* Host */ && !sameHostView(injector)) {
                injector = null;
            }
            else {
                injector = injector.parent;
            }
        }
    }
    // No directive was found for the given token.
    if (flags & 8 /* Optional */)
        return null;
    throw new Error("Injector: NOT_FOUND [" + stringify$1(token) + "]");
}
function getOrCreateInjectable(di, token, flags) {
    if (flags === void 0) { flags = 0 /* Default */; }
    var bloomHash = bloomHashBit(token);
    // If the token has a bloom hash, then it is a directive that is public to the injection system
    // (diPublic). If there is no hash, fall back to the module injector.
    if (bloomHash === null) {
        var moduleInjector = getPreviousOrParentNode().view[INJECTOR$1];
        var formerInjector = setCurrentInjector(moduleInjector);
        try {
            return inject(token, flags);
        }
        finally {
            setCurrentInjector(formerInjector);
        }
    }
    else {
        var injector = di;
        while (injector) {
            // Get the closest potential matching injector (upwards in the injector tree) that
            // *potentially* has the token.
            injector = bloomFindPossibleInjector(injector, bloomHash, flags);
            // If no injector is found, we *know* that there is no ancestor injector that contains the
            // token, so we abort.
            if (!injector) {
                break;
            }
            // At this point, we have an injector which *may* contain the token, so we step through the
            // directives associated with the injector's corresponding node to get the directive instance.
            var node = injector.node;
            var nodeFlags = node.tNode.flags;
            var count = nodeFlags & 4095 /* DirectiveCountMask */;
            if (count !== 0) {
                var start = nodeFlags >> 14 /* DirectiveStartingIndexShift */;
                var end = start + count;
                var defs = node.view[TVIEW].directives;
                for (var i = start; i < end; i++) {
                    // Get the definition for the directive at this index and, if it is injectable (diPublic),
                    // and matches the given token, return the directive instance.
                    var directiveDef = defs[i];
                    if (directiveDef.type === token && directiveDef.diPublic) {
                        return node.view[DIRECTIVES][i];
                    }
                }
            }
            // If we *didn't* find the directive for the token and we are searching the current node's
            // injector, it's possible the directive is on this node and hasn't been created yet.
            var instance = void 0;
            if (injector === di && (instance = searchMatchesQueuedForCreation(node, token))) {
                return instance;
            }
            // The def wasn't found anywhere on this node, so it was a false positive.
            // If flags permit, traverse up the tree and continue searching.
            if (flags & 2 /* Self */ || flags & 1 /* Host */ && !sameHostView(injector)) {
                injector = null;
            }
            else {
                injector = injector.parent;
            }
        }
    }
    // No directive was found for the given token.
    if (flags & 8 /* Optional */)
        return null;
    throw new Error("Injector: NOT_FOUND [" + stringify$1(token) + "]");
}
function getOrCreateInjectable ( di , token , flags ) { if ( flags === void 0 ) { flags = 0 /* Default */ ; } var bloomHash = bloomHashBit ( token ) ; // If the token has a bloom hash, then it is a directive that is public to the injection system // (diPublic). If there is no hash, fall back to the module injector. if ( bloomHash === null ) { var moduleInjector = getPreviousOrParentNode ( ) . view [ INJECTOR$1 ] ; var formerInjector = setCurrentInjector ( moduleInjector ) ; try { return inject ( token , flags ) ; } finally { setCurrentInjector ( formerInjector ) ; } } else { var injector = di ; while ( injector ) { // Get the closest potential matching injector (upwards in the injector tree) that // *potentially* has the token. injector = bloomFindPossibleInjector ( injector , bloomHash , flags ) ; // If no injector is found, we *know* that there is no ancestor injector that contains the // token, so we abort. if ( ! injector ) { break ; } // At this point, we have an injector which *may* contain the token, so we step through the // directives associated with the injector's corresponding node to get the directive instance. var node = injector . node ; var nodeFlags = node . tNode . flags ; var count = nodeFlags & 4095 /* DirectiveCountMask */ ; if ( count !== 0 ) { var start = nodeFlags >> 14 /* DirectiveStartingIndexShift */ ; var end = start + count ; var defs = node . view [ TVIEW ] . directives ; for ( var i = start ; i < end ; i ++ ) { // Get the definition for the directive at this index and, if it is injectable (diPublic), // and matches the given token, return the directive instance. var directiveDef = defs [ i ] ; if ( directiveDef . type === token && directiveDef . diPublic ) { return node . view [ DIRECTIVES ] [ i ] ; } } } // If we *didn't* find the directive for the token and we are searching the current node's // injector, it's possible the directive is on this node and hasn't been created yet. var instance = void 0 ; if ( injector === di && ( instance = searchMatchesQueuedForCreation ( node , token ) ) ) { return instance ; } // The def wasn't found anywhere on this node, so it was a false positive. // If flags permit, traverse up the tree and continue searching. if ( flags & 2 /* Self */ || flags & 1 /* Host */ && ! sameHostView ( injector ) ) { injector = null ; } else { injector = injector . parent ; } } } // No directive was found for the given token. if ( flags & 8 /* Optional */ ) return null ; throw new Error ( "Injector: NOT_FOUND [" + stringify$1 ( token ) + "]" ) ; }
Searches for an instance of the given directive type up the injector tree and returns
that instance if found.

Specifically, it gets the bloom filter bit associated with the directive (see bloomHashBit),
checks that bit against the bloom filter structure to identify an injector that might have
the directive (see bloomFindPossibleInjector), then searches the directives on that injector
for a match.

If not found, it will propagate up to the next parent injector until the token
is found or the top is reached.

@param di Node injector where the search should start
@param token The directive type to search for
@param flags Injection flags (e.g. CheckParent)
@returns The instance found
Searches for an instance of the given directive type up the injector tree and returns that instance if found .