Angular 1.5 component method templateUrl + function

后端 未结 3 1675
温柔的废话
温柔的废话 2020-11-30 11:00

I\'m trying to get an app working with angular 1.5.0-beta.2

To make a \'directive\' I have the following code:

myApp.component(\'gridshow\', {
  bind         


        
3条回答
  •  一整个雨季
    2020-11-30 11:38

    I solved this problem by following technique. This may help you.

    Template

    A component

    /**
     * @ngdoc Component
     * @name app.component.renderField
     * @module app
     *
     * @description
     * A component to render Field by type
     *
     * @author Mohan Singh ( gmail::mslogicmaster@gmail.com, skype :: mohan.singh42 )
     */
    (function () {
      'use strict';
    
      angular
        .module('app')
        .component('renderField', {
          bindings: {
            fieldType: '@',
          },
          template: '
    ', controller: [ function () { var $ctrl = this; $ctrl.$onInit = initialization; $ctrl.$onDestroy = onDestroy; $ctrl.$onChanges = onChanges; /** * public properties */ /** * public methods */ /** * @function * @name initialization * @description * A component's lifeCycle hook which is called after all the controllers on an element have been constructed and had their bindings initialized */ function initialization() { } /** * @function * @name onChanges * @description * A component's lifeCycle hook which is called when bindings are updated. */ function onChanges(bindings) { if(bindings.fieldType && bindings.fieldType.isFirstChange()){ //$ctrl.fieldType['text' | 'textarea' | 'select' | 'radio'] $ctrl.templateUrl = 'partials/fields/'+$ctrl.fieldType+'.html'; } } /** * @function * @name onDestroy * @description * A component's lifeCycle hook which is called when is called on a controller when its containing scope is destroyed. * Usefull to release external resources, watches and event handlers. */ function onDestroy() { } }] }); })();

提交回复
热议问题