Я пробовал использовать методы DOM и stateProvider.Угловой контроллер, вызываемый дважды
Feed.html
<div class="container-fluid">
<div class="panel panel-card" ng-repeat="post in posts" class="col-lg-12 fadeInUp animated" style="-webkit-animation-delay: {{$index * 0.1}}s; animation-delay: {{$index * 0.1}}s;">
<div class="panel-body bg-primary">{{post.user_id}} from {{post.squad_id}}</div>
<div class="clearfix"></div>
</div>
</div>
feed.controller.js
(function() {
'use strict';
angular
.module('app')
.controller('FeedController', FeedController);
FeedController.$inject = ['$scope'];
function FeedController($scope) {
console.log($scope);
}
})();
routes.config.js
(function() {
'use strict';
angular
.module('app')
.config(routesConfig);
routesConfig.$inject = ['$locationProvider', '$stateProvider', '$urlRouterProvider', 'RouteProvider'];
function routesConfig($locationProvider, $stateProvider, $urlRouterProvider, Route) {
// use the HTML5 History API
$locationProvider.html5Mode(false);
// Default route
//$urlRouterProvider.otherwise('/feed');
// Application Routes States
$stateProvider
.state('app', {
url: '',
abstract: true,
templateUrl: Route.base('app.html'),
resolve: {
_assets: Route.require('icons', 'toaster', 'animate')
}
})
.state('app.feed', {
url: '/feed/',
templateUrl: Route.base('feed.html'),
controller: "FeedController",
resolve: {}
})
}
})();
Другой ш ау было вставить ng-controller="FeedController"
в верхний DIV в feed.html
и закомментируйте controller: "FeedController",
от routes.config.js
app.html
<!-- top navbar-->
<header ng-include="'templates/top-navbar.html'" ng-class="app.theme.topbar"></header>
<!-- Sidebar-->
<aside ng-include="'templates/sidebar.html'" ng-class="app.theme.sidebar"></aside>
<!-- Main-->
<section>
<!-- Content-->
<div ui-view="" autoscroll="false" ng-class="app.views.animation" class="app"></div>
</section>
<!-- Page footer-->
<footer ng-include="'templates/footer.html'"></footer>
Оба эти методы console.log ($) объем в два раза с разными $ идентификаторами. Это происходит при перезагрузке страницы и изменении состояния.
У кого-нибудь есть идеи?
Я думаю, что вы обертываете тело только 'FeedController'. –
Что вы имеете в виду? –
Что такое 'RouteProvider'? –