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