Angular 需要将工作代码移动到部分或其他内容以显示在其他页面下 html

Angular need to move working code into a partial or something to display under other page html

我有一个 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

的controller/module/database
<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" />


根据 OP

的建议更新 2

当前 controller.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 }}
    }
 };
});

common文件夹里好像没有module.js,有一个directives.js和controller.js 但是我看到 links 文件夹中有这个代码

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-groupdirective 逃脱惩罚。转换非常简单(如果您在控制器中使用 $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>