Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 学习角度-这是将div链接到服务的正确方法吗?_Angularjs - Fatal编程技术网

Angularjs 学习角度-这是将div链接到服务的正确方法吗?

Angularjs 学习角度-这是将div链接到服务的正确方法吗?,angularjs,Angularjs,我正在学习Angular,我想知道是否有更好的方法将此指令链接到我的服务 我最想知道的是,在模型中将Guid存储为Id,然后在服务中引用该Id是否是链接指令和服务的好方法?还是有一种更“有角度”的方法来做到这一点 指令: myApp.directive("myDialog", ['$compile', function ($compile) { return { restrict: 'E', scope: { model: "="

我正在学习Angular,我想知道是否有更好的方法将此指令链接到我的服务

我最想知道的是,在模型中将Guid存储为Id,然后在服务中引用该Id是否是链接指令和服务的好方法?还是有一种更“有角度”的方法来做到这一点

指令:

myApp.directive("myDialog", ['$compile', function ($compile) {
    return {
        restrict: 'E',
        scope: {
            model: "="
        },
        template: "<div id='dialog_{{model.dialogId}}' ng-include='model.templateUrl' style='display: none'></div>",
        replace: true
}]);

这似乎是工厂模式。我见过有人用这种方法,角度很好,是一种很好的方法

myApp.service("myDialogSvc", function () {
    // This will be called by the controller
    this.init = function (template) {
        var model = {};

        model.template = template;

        var id = newGuid();  // Gets a new Guid -- defined elsewhere
        model.dialogId = id;

        return model;
    }

    this.open = function (model) {

        $("#dialog_" + model.dialogId).dialog({
            modal: true
        });
    }
});