У меня есть Angular SPA, в котором все работает нормально, за исключением того, что бизнес хочет, чтобы я переместил код из этой link-group.html (у которого есть свой собственный контроллер, модуль и т.д.).
URL-адрес с кодом для размещения в шаблоне или поместить код под другим html-кодом supervisors.html
URL для новостей, который находится в link-group.html, который мне нужно переместить:
http://localhost:1337/doc-home/#/tips/2?paginatePage=1
Файл:
link-group.html
Место нахождения:
Затем укажите место, где мне нужно отобразить (переместить)
URL:
http://localhost:1337/doc-home/#/supervisors
Файл:
supervisors.html
Место нахождения:
Шаблон? контрольная ссылка?
ОБНОВИТЬ
Я хочу взять весь код из link.group.html и перенести его на страницу supervisor.html
Тем не менее, существует специальный код, который ссылается на контроллер/модуль/базу данных, которая основана на URL-адресе
<div class="links-group" ng-repeat="group in groups" ng-show="!group.hidden">
<div ng-show="!edit" style="margin: 5px 0;">
<h3>{{ group.title }}</h3>
<div ng-show="edit === true">
<input style="margin: 5px 0" placeholder="title..." class="input" ng-model="group.title" />
ОБНОВЛЕНИЕ 2 за предложение от ОП
Текущий контроллер.js для supervisor.html
angular.module('supervisors')
.controller('SupervisorsCtrl',
function ($scope, UserService) {
UserService.get(function (err, user) {
$scope.user = user;
});
});
Итак, чтобы изменить, могу ли я добавить еще один модуль под ним?
angular.module('supervisors')
.controller('SupervisorsCtrl',
function ($scope, UserService) {
UserService.get(function (err, user) {
$scope.user = user;
});
});
angular.module('linkgroup', ['ng'])
.directive('linkgroup', function({{ dependencies of your controller here }}) {
return {
templateUrl: {{ url of the template, likely link-group.html }},
link: function($scope, $element, $attributes) {
// think of this as the controller of a directive
{{ code of your controller,
replace 'this' with '$scope' if you used ControllerAs }}
}
};
});
Кажется, что в общей папке нет модуля module.js, есть директивы.js и controller.js Однако я вижу, что с папкой ссылок есть этот код
angular.module('links')
.controller('LinksCtrl', function ($scope, LinksService, SearchService, UserService, notify, $window, $location) {
$scope.message = "";
UserService.get(function (err, user) {
if (err) {
notify.error('Error getting current user.');
} else {
if (user.groups.WEB_ESO !== true) {
$location.path('/');
}
}
});
Похоже, вы можете уйти с директивой, которая содержит вашу link-group
. Трансформация довольно проста (если вы использовали $scope
в своем контроллере, это почти прямая копия + вставка):
angular.module('linkgroup', ['ng'])
.directive('linkgroup', function({{ dependencies of your controller here }}) {
return {
templateUrl: {{ url of the template, likely link-group.html }},
link: function($scope, $element, $attributes) {
// think of this as the controller of a directive
{{ code of your controller,
replace 'this' with '$scope' if you used ControllerAs }}
}
};
});
Затем в supervisors.html
добавьте <linkgroup></linkgroup>
внизу.