一个指令返回中有多种方法

问题描述 投票:1回答:1

我仅使用一个指令为我的Web应用程序设置基本模板,而多个方法返回不同的模板。

到目前为止,我所做的与我所说的服务相同”

SERVICE

app.service('myService', function() {
    let path = "app/api/";

    return {
        getStudentInfo: () => {
            //Some Statement...
        }
    }
})

现在,以防我目前如何称呼指令。但似乎不起作用

目录

app.directive('baseTemplate', function() {
    let path = "app/templates/"; // my basetemplate path folder

    // I want to call specific methods returning the template I need.
    return {
        getCategory: () => {
            return {
                restrict: 'A',
                template: '<strong> HELLO WORLD! </strong>'
            }
        },
        getTable: () => {
            return: {
                restrict: 'A',
                template: '<table> SOME DATA! </table>'
            }
        }
    }
})

这就是我在调用指令时所做的

HTML

<div base-template.getCategory>
    //The Output should be <strong> HELLO WORLD! </strong>
</div>

<div base-template.getTable> 
    //The same as the above Out should <table> SOME DATA! </table>
</div>

我仅使用一个具有多个方法返回不同模板的指令为我的Web应用程序设置基本模板。到目前为止,我所做的与我称呼服务...

angularjs angularjs-directive
1个回答
0
投票

一个人可以这样:

© www.soinside.com 2019 - 2024. All rights reserved.