ngmaterial-mdcompiler
v1.0.2
Published
The $mdCompiler service ripped from angular material
Downloads
3
Readme
ngmaterial-mdcompiler
The $mdCompiler service ripped from angular material
Install
$ npm install --save ngmaterial-mdcompiler
Usage
const angular = require('angular')
const mdCompiler = require('ngmaterial-mdcompiler')
angular.module('myApp', [
require('ngmaterial-mdcompiler')
])
.controller('MyCtrl', function ($mdCompiler) {
// $mdCompiler.compile({ ... })
})
API
The module is exposed as a string representing the module's name for easy inclusion (see above).
It creates a service $mdCompiler
.
$mdCompiler.compile(options) -> Promise<compileData>
A helper to compile an HTML template/templateUrl with a given controller, locals, and scope.
options
An options object, with the following properties:
controller
-{(string=|function()=}
Controller fn that should be associated with newly created scope or the name of a registered controller if passed as a string.controllerAs
-{string=}
A controller alias name. If present the controller will be published to scope under thecontrollerAs
name.template
-{string=}
An html template as a string.templateUrl
-{string=}
A path to an html template.transformTemplate
-{function(template)=}
A function which transforms the template after it is loaded. It will be given the template string as a parameter, and should return a a new string representing the transformed template.resolve
-{Object.<string, function>=}
- An optional map of dependencies which should be injected into the controller. If any of these dependencies are promises, the compiler will wait for them all to be resolved, or if one is rejected before the controller is instantiatedcompile()
will fail..key
-{string}
: a name of a dependency to be injected into the controller.factory
-{string|function}
: Ifstring
then it is an alias for a service. Otherwise if function, then it is injected and the return value is treated as the dependency. If the result is a promise, it is resolved before its value is injected into the controller.
locals
-{object}
: The locals which will be passed into the controller oncelink
is called. IfbindToController
is true, they will be copied to the ctrl insteadbindToController
-bool
: bind the locals to the controller, instead of passing them in.
returns Promise<compileData>
Returns a promise, which will be resolved with a compileData
object.
compileData
has the following properties:
element
-{element}
: an uncompiled element matching the provided template.link
-{function(scope)}
: A link function, which, when called, will compile the element and instantiate the provided controller (if given).