M
M
Maxim Ivanov2016-09-16 19:00:49
Angular
Maxim Ivanov, 2016-09-16 19:00:49

How to connect another directive (component) in Angular?

I have 2 directives and 2 files (login.html and main.html)
Inside the html files we need to connect other components
Now the logic is like this, but the components inside are not connected:
index.html

<body>
<login-content></login-content>
</body>

app.js
window.app = angular.module("myApp", []);
import loginComponent from './angular/directives/loginContent.js';
app.directive('loginContent', loginComponent);

// ..

loginContent.js
export default function() { 
  return { 
    restrict: 'E', 
    scope: { 
      info: '=' 
    }, 
    templateUrl: 'public/html/login.html' 
  }; 
}

login.html
<div class="row" ng-controller="LoginController">
 
     <navigation></navigation>
     <widgets></widgets>

</div>

The problem is how LoginController should be able to connect these same directives (components), explain?
LoginController
/**
 * Контроллер, обрабатывающий компонент формы входа и регистрации
 * @param {object} $rootScope - общая область видимости шаблонов для приложения 
 * @param {object} $http - ajax-объект для работы с http-запросами
 * @param {object} $compile - объект для добавления нового DOM и связывания с обработчиками
 * @param {object} $scope - локальная область видимости шаблонов относительно компонента контроллера
 * @param {object} dataService - сервис, обменивающийся данными между контроллерами
 */
export default ($rootScope, $http, $compile, $scope, dataService) => {

    // пытался сделать так
    app.directive('navigation', require('./../directives/navContent.js'));
    // но пишет, что app пустой и нет такого метода 

}

and how, for example, it is possible to connect nested components?
for example, in the definition of the widgets component inside the html template, there can be a pagination component, but how will it then be connected by the widgets component?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2016-09-16
@splincodewd

So it won't work. You are trying to do something like "lazy" loading.
Declare all directives before starting the application.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question