AngularJs TemplateUrl

时间:2014-09-29 15:39:16

标签: angularjs angularjs-directive angularjs-scope

我有两个指令,我想用attr动态模板。

例如; 我想发送带有deviceEmpty标签的attr。如果此标记不为null,请使用此标记。如果此标记使用静态URL。

AngularJs

directive('deviceEmpty', [function (scope) {
                return {
                    restrict: 'E',
                    templateUrl:'prototype.html',
                    link: function (scope) {
                        scope.value = 1;


                    }

                };
            }]).
            directive('screen', [function ($scope) {
                return {
                    restrict: 'E',
                    templateUrl:function(elem,attrs) {
                        return  attrs.templateUrl || 'device_screens/{{homePageValue}}.html'|| 'device_screens/splash.html'

                    },
                    link:function(scope){
                    }


                };
            }]);

的index.html

<device-Empty alternative-Home-Page="homePageAlternative-1"></device-Empty>

prototype.html

<screen template-url="device_screens/splash.html"  ng-switch-when="1"></screen>
<screen template-url="device_screens/samsung-screen-1.html"  ng-switch-when="2"></screen>

0 个答案:

没有答案