How to conditionally apply a template via custom Angular directives?

后端 未结 6 804
攒了一身酷
攒了一身酷 2020-12-29 02:37

DEMO

Consider the following directive:

angular.module(\'MyApp\').directive(\'maybeLink\', function() {
  return {
    replace: true,
    s         


        
6条回答
  •  春和景丽
    2020-12-29 02:48

    You can use ng-if for the same

    Below is the working example

    Working Demo

    Directive Code:

    angular.module('MyApp').directive('maybeLink', function() {
      return {
        replace: true,
        scope: {
          maybeLink: '=',
          maybeLinkText: '='
        },
        template: '' + 
                  '  ' +
                  '  ' +
                  '',
        controller: function($scope) {
          $scope.text = $scope.maybeLinkText.replace(/\n/g, '
    '); } }; });

提交回复
热议问题