네는, 컨트롤러가있는 페이지에 지금까지 내 AngularJS와의 모든 일을하는 데
var app = angular.module('myApp', []);
app.service('tooltips', function() {
this.getTooptip = function(pageId) {
...
};
});
function myController($scope, tooltips) {
$scope.pageId = '<pageID>'
$scope.tooltip = tooltips.getTooltip($scope.pageId);
}
, 나는에 혼동되었다 컨트롤러가 선언되지 않은 페이지에서 작업하십시오. 답변 : ng-app가 실행되고있는 한 확실합니다. 그래서 페이지가 도구 설명을 요구 한 알아 내기 위해 툴팁라는 지시를 작성, 툴팁을 필요로 각 페이지의 포장 사업부에 툴팁을 추가하고의 데이터를로드하는 서비스를 사용
HTML :.
<div class="pagewrapper" tooltip data-title="unique-page-title">
JSON :
[{
"extension": "unique-page-title",
"contents": [
{
"head": "Tooltip heading one",
"content": "information on section 1"
},
{
"head": "Tooltip heading two",
"content": "information on section 2"
}
]
}]
JS : 당신이 지침에 대해
angular.module('myApp.services', []).service('tooltips', function ($http) {
var requestPromise = $http.get('path/to/tooltips.json').then(function (d) {
return d.data;
});
this.getTooltips = function() {
return requestPromise;
};
});
angular.module('myApp.directives', []).directive('tooltip', function (tooltips, $filter) {
return {
restrict: 'A',
link: function (scope, element, attr) {
var elements = $('.forms .tooltip'),
list = [],
title = attr.title;
//use the promisey service getTooltips to load the tooltips JSON
tooltips.getTooltips().then(function (tips) {
//Do some things to identify the correct place to insert the tooltip content, and insert it.
});
}
};
});
출처
2013-11-14 17:57:11
Ila
을 알고 계십니까? –