Passing value of a variable to angularjs directive template function

后端 未结 3 1454
长发绾君心
长发绾君心 2021-02-04 11:03

I am trying to pass a $scope\'s variable to a directive, but its not working. I am catching the variable in the template function:

app.directive(\'customdir\', f         


        
3条回答
  •  执笔经年
    2021-02-04 11:32

    Or like this

    app.directive('customdir', function ($compile) {
      var getTemplate = function(filter) {
        switch (filter) {
          case 'World': return '';
          default:  return '';
        }
      }
    
        return {
            restrict: 'E',
            scope: {
              filterby: "="
            },
            link: function(scope, element, attrs) {
                var el = $compile(getTemplate(scope.filterby))(scope);
                element.replaceWith(el);
            }
        };
    });
    

    http://plnkr.co/edit/yPopi0mYdViElCKrQAq9?p=preview

提交回复
热议问题