AngularJS directive dynamic templates

前端 未结 4 1586
悲&欢浪女
悲&欢浪女 2020-12-04 08:06

I\'m trying to make directive with differtent templates based on scope value.

This is what i done so far which i don\'t know why doesn\'t work http://jsbin.com/mibey

4条回答
  •  情歌与酒
    2020-12-04 08:54

    You can also do it very straightforward like this:

    appDirectives.directive('contextualMenu', function($state) {
        return {
          restrict: 'E',
          replace: true,
          templateUrl: function(){
            var tpl = $state.current.name;
            return '/app/templates/contextual-menu/'+tpl+'.html';
          }
        };
    });
    

提交回复
热议问题