Animations in partial views is not working - angularjs

I'm attempting to use ng-view to produce a simple slide effect between views. I am not sure If I am doing it right. The codes is as follows:
Script: (1.15)
<script src="js/lib/angular-1.1.5/angular.min.js"></script>
Routing:
app.config(function ($routeProvider) {
$routeProvider.
when("/", { templateUrl: "partials/loading.html" }).
when("/session", {templateUrl: "partials/session.html", controller: "TimerController" }).
when("/settings", { templateUrl: "partials/settings.html", controller: "SettingsController" }).
otherwise({ redirectTo: "/" });
HTML containing ng-view and ng-click used to switch views:
<div class="flex-container viewport">
<div class="flex-item-1">
<div>
<button class="overlay btn icon-cog" ng-click="changeView('/settings')" type="button"></button>
</div>
</div>
<div ng-view class="flex-item-2" ng-animate="{enter: 'enter', leave: 'leave'}"></div>
<div class="flex-item-3">
<div>
<button class="btn btn-5 btn-5a icon-cog" ng-click="setTimer(3)">
<span>3</span>
</button>
</div>
<div>
<button class="btn btn-5 btn-5a icon-cog" ng-click="setTimer(5)">
<span>5</span>
</button>
</div>
<div>
<button class="btn btn-5 btn-5a icon-cog" ng-click="setTimer(10)">
<span>10</span>
</button>
</div>
<div>
<button class="btn btn-5 btn-5a icon-cog" ng-click="setTimer(15)">
<span>15</span>
</button>
</div>
</div>
Controller fn used to switch views:
$scope.changeView = function (view) {
$location.path(view);
};
CSS used to implement animation effect:
.enter-setup {
position:absolute;
-webkit-transition: 3.3s ease-out all;
-webkit-transform:translate3d(100%,0,0);
}
.enter-setup.enter-start {
position:absolute;
-webkit-transform:translate3d(0,0,0);
}
.leave-setup {
position:absolute;
-webkit-transition: 3.3s ease-out all;
-webkit-transform:translate3d(0,0,0);
}
.leave-setup.leave-start {
position:absolute;
-webkit-transform:translate3d(-100%,0,0);
}
The content still shows (but now with a flicker) and the slide animations do not work. Any help would be appreciated.
Update: I fixed the css syntax to 1.15. Unfortuneatly it still isn't working. I'm using flexbox and I'm thinking this is the cause of the problem. Anyone have similar problems when using ng-animate + flexbox?

You are using the 1.1.5 version, but the CSS sintaxe that you are using is from 1.1.4.
The correct is enter-active instead of enter-start and just enter instead of enter-setup
Take a look at the 1.1.5 documentation
And check some samples at NG Animate Sample Site
And if you use just -webkit-transform, this will work only in chrome and safari... Add the others vendors too.

Related

Using a controller as uibModal Controller

So I am working on a module called "ShowTree".
Before this, I have a controller named "InviteUserCtrl". Inside the ShowTree module, there is a button that will show a uibModal that is used to add new user.
Basically this uibModal in ShowTreeCtrl is all exactly the same as InviteUserCtrl. So, instead of copy pasting all the code from the InviteUserCtrl to the new uibModalController, I decided to inject the InviteUserCtrl as the uibModalController.
The problem is I can't use the InviteUserCtrl as my uibModalController
here is my html code in ShowTree list.html
<div ng-controller="inviteUserCtrl as vm">
<script type="text/ng-template" id="inviteUser.html">
<div class="modal-header">
<h3 class="modal-title">Invite User</h3>
</div>
<div class="modal-body">
<span ng-include="'app_view/modules/invite_user/form.html'"></span>
<br><br>
</div>
<div class="modal-footer">
<button class="btn btn-warning" type="button" ng-click="vm.cancel()">Back</button>
</div>
</script>
</div>
here is the code in my ShowTreeCtrl
function open(size){
var modalInstance = $uibModal.open({
animation : true,
templateUrl: 'inviteUser.html',
controller: 'inviteUserCtrl as vm',
size: size,
});
}
Also i am using ui-router. here is my code in the router
.state('app.show_tree', {
url: '/show_tree/:action/:id',
templateUrl: base_view_url+'modules/show_tree/index.html',
data : { title: 'Show Tree' },
controller : "showTreeCtrl",
controllerAs : "vm",
resolve: load([
base_view_url+'modules/show_tree/showTreeCtrl.js',
base_view_url+'modules/invite_user/inviteUserCtrl.js',
'ui.select'
]),
params : {action:"list",id:null},
activetab: 'Activity'
})
The above code is able to display the form from the InviteUser module, but the controller seems doesn't work. The form button and the controller API do not run at all.
What am I missing here? thank you ..

Angular Scroll on Click

I am having an issue getting Angular Scroll to work.I am trying to scroll from the landing div to another section on the page with a button click. My code formatted really strangely, so let me know if further clarification is needed.
HTML
<div class="cover">
<div class="big-logo">
<i class="fa fa-trello"></i>
<span> My Kanban</span>
<br>
<button class="arrow" ng-click="bc.toLists()" du-smooth-scroll>
<i class="fa fa-angle-double-down fa-sm animated flash infinite" aria-hidden="true"></i>
</button>
</div>
</div>
<div class="story-board content">
<button class="add-list" ng-click="bc.addingList = !bc.addingList">
Add List
</button>
<div ng-if="bc.addingList">
<form ng-submit="bc.addList(bc.newList)">
<input style="margin-left: 5px" ng-model="bc.newList.name"/>
<button type="submit">+</button>
</form>
</div>
<div class="list" ng-repeat="list in bc.lists">
<button style="font-size: 10px;background: none;border:none; color: black" ng-click="bc.removeList(list)">x</button>
<list-component list-obj="list"></list-component>
</div>
</div>
init.js
angular.module('kanban', ['duScroll'])
app.js
angular.module('kanban')
.component('boardComponent', {
templateUrl: 'app/components/board/board.html',
controller: BoardController,
controllerAs: 'bc'
})
BoardController.$inject = ['EsService']
function BoardController(EsService) {
var bc = this;
bc.lists = EsService.getLists();
bc.addingList = false;
bc.removeList = function(list){
EsService.removeList(list.id);
}
bc.addList = function(list){
EsService.createList(list);
bc.newList = {};
}
bc.toLists = function() {
bc.cover = angular.element(document.getElementsByClassName('cover'));
bc.content = angular.element(document.getElementsByClassName('content'));
bc.cover.scrollTo(bc.content, 0, 1000);
}
}
For a JQuery free answer, you can use $anchorScroll
Create your anchor link:
<button ng-click="$ctrl.scrollTo('anid')">Scroll</button>
Create the anchor to scroll to:
<div id="anid">Land here</div>
Then your controller:
controller: function($anchorScroll) {
this.scrollTo = function(id) {
$anchorScroll(id);
}
}
I would recommend letting your controller handle the scrolling as opposed to the directives. You will have much tighter control that way and can therefore debug any issues.
Here's an example using the scrollToElement method. Once you have this logic in place you can switch it out to any method you need.
Here's a working demo
angular
.module('app', ['duScroll'])
.component('cmpExample', {
templateUrl: 'path/to/template.html',
controller: function($document) {
var vm = this;
vm.scrollTo = function(id) {
$document
.scrollToElement(
angular.element(document.getElementById(id)), 0, 1000
);
}
}
});
html
<button ng-click="$ctrl.scrollTo('target')">
<div id="target">Content further down the page</div>

ngAnimate 1.5.6 not adding enter and leave classes to ng-view

Using Angular and angular-animate, both are 1.5.6
I am not having success with ngAnimate. From what I can tell, the classes ng-enter and ng-leave are not being added to <div class="col-xs-12 view-animation" ng-view></div>. What am I doing wrong?
index.html:
<body ng-app="gulpNewy">
<div id="sidebar-back-drop"></div>
<div class="row">
<div id="sidebar-bar-static">
Home
Examples
</div>
</div>
<div class="viewport row">
<div class="col-xs-12 view-animation" ng-view></div>
</div>
css:
.ng-enter, .view-animation.ng-enter {
left: 500px;
}
.ng-leave, .view-animation.ng-leave-active, .view-animation.ng-leave {
left: -500px;
}
app.js:
var gulpNewy =
angular
.module('gulpNewy', ['ngRoute', 'ngAnimate'])
.config(function($routeProvider) {
$routeProvider
.when('/home', {
templateUrl: 'views/home.html',
controller: 'homeCtrl'
})
.when('/examples', {
templateUrl: 'views/examples.html'
})
$routeProvider.otherwise({ redirectTo: '/home'});
});
The issue was the animation was happening to quick. Once I used
.view-animation {
-webkit-transition: 1s;
}
I could see the animation.
You need change class from controller. See https://www.google.com.ar/url?sa=t&source=web&rct=j&url=http://www.nganimate.org/&ved=0ahUKEwi_puevzonNAhXGlR4KHT-yApoQFggbMAE&usg=AFQjCNFuh3t3sGVMwBfRRh50fkenHFUpGw&sig2=9asfdX8gJs0msLmwyezNnA

Angular JS - the common issue of two apps using the same route provider

Hey all and thanks for reading.
I have a client side set of text blurb I wanted to feed through views using ng.
My problem is that although I feel I have this set up correctly, I only ever see a repetition of the first view on the second view and have lost functionality on the first view anchors to change the text blurbs.
I was wondering if anyone could shed some light on it for me at all.
It been a while since I did anything angularJS, I forgot how fun yet brick walling it can be.
I post the app.js code below
var animateDesign = angular.module('animateDesign', ["ngAnimate", "ngRoute"]);
animateDesign.config(['$routeProvider', function($routeProvider){
$routeProvider.
when('/background', {templateUrl: './assets/views/design/background.html',
css: ['./assets/vendor/bootstrap-3.2.0-dist/css/bootstrap.min.css', 'assets/css/after_bs.css']}).
when('/logo', {templateUrl: './assets/views/design/logo.html',
css: ['./assets/vendor/bootstrap-3.2.0-dist/css/bootstrap.min.css', 'assets/css/after_bs.css']}).
when('/branding', {templateUrl: './assets/views/design/branding.html',
css: ['./assets/vendor/bootstrap-3.2.0-dist/css/bootstrap.min.css', 'assets/css/after_bs.css']}).
when('/illustration', {templateUrl: './assets/views/design/illustration.html',
css: ['./assets/vendor/bootstrap-3.2.0-dist/css/bootstrap.min.css', 'assets/css/after_bs.css']}).
when('/print', {templateUrl: './assets/views/design/print.html',
css: ['./assets/vendor/bootstrap-3.2.0-dist/css/bootstrap.min.css', 'assets/css/after_bs.css']}).
when('/web', {templateUrl: './assets/views/design/web.html',
css: ['./assets/vendor/bootstrap-3.2.0-dist/css/bootstrap.min.css', 'assets/css/after_bs.css']}).
otherwise({redirectTo: '/background'});
}])
.animation('.reveal-animation-design', function($scope) {
return {
enter: function(element, done) {
element.css('display', 'none');
element.fadeIn(1500, done);
return function() {
element.stop();
}
},
leave: function(element, done) {
element.fadeOut(1500, done)
return function() {
element.stop();
}
}
}
});
angular.bootstrap(document.getElementById("animatePrint"), ['animatePrint']);
var animatePrint = angular.module('animatePrint', ["ngAnimate", "ngRoute"]);
animatePrint.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/litho', {templateUrl: './assets/views/print/litho.html',
css: ['./assets/vendor/bootstrap-3.2.0-dist/css/bootstrap.min.css', 'assets/css/after_bs.css']}).
when('/digital', {templateUrl: './assets/views/print/digital.html',
css: ['./assets/vendor/bootstrap-3.2.0-dist/css/bootstrap.min.css', 'assets/css/after_bs.css']}).
when('/other', {templateUrl: './assets/views/print/other.html',
css: ['./assets/vendor/bootstrap-3.2.0-dist/css/bootstrap.min.css', 'assets/css/after_bs.css']}).
otherwise({redirectTo: '/litho'});
}])
.animation('.reveal-animation-print', function() {
return {
enter: function(element, done) {
element.css('display', 'none');
element.fadeIn(1500, done);
return function() {
element.stop();
}
},
leave: function(element, done) {
element.fadeOut(1500, done)
return function() {
element.stop();
}
}
}
});
I will also post the html implementation too, as it could just be debugging blindness and likely the simplest thing
<div class="col-md-6">
<div class="container">
<div ng-app="animateDesign">
<div class="wrapper">
<div ng-view class="reveal-animation-design">
This is the background area
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!--/.container-->
</div>
<!--/#design-->
<div id="print" class="page-section">
<div class="container">
<h2> Print </h2>
<div class="row">
<div class="col-md-3 no-float">
<!--start Vertical Header Test-->
<nav class="navbar navbar-left" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-nav">
<button type="button" id="nav-toggle" class="navbar-toggle" data-toggle="collapse" data-target="#alt-nav">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"><img src="assets/img/png/dd-logo-basic-sm.png"/></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div id="alt-nav" class="collapse navbar-collapse">
<ul class="nav navbar-left">
<li>litho</li>
<li>digital</li>
<li>other</li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
</div>
<div class="col-md-6 no-float">
<div class="container">
<!--this is not showing on the page TODO: animatePrint needs to show on page, before using id="animatePrint" and having a default otherwise call to be the background-->
<div id="animatePrint">
<div class="wrapper">
<div ng-view class="reveal-animation-print">
</div>
</div>
</div>
</div>
</div>
</div>
<!--/.row-->
</div>
<!--/.container-->
</div>
<!--/.print-->
Thank you in advance for any help shedding light on this.
Cheers all and thanks again for reading:)
P.S> Could someone please help me/ guide me to format the code too, it seems like it wont accept the code line after my first declared line - sry still a bit new.
I had to add as a snippet, to get any success posting - (me noob)
Gruffy :)

Angular ui-router crashing browsers

So I have no idea what is wrong, but im assuming i have a loop running in the background of my code or that im routing incorrectly. But all i know is when i try to go to my index page, my entire browser is taken down, no errors or anything, just crashing. Any help would really be appreciated im just trying to move on from this problem.And in case this changes anything i am using a rails backend.
planoxApp.config(['$stateProvider','$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/',
templateUrl: 'templates/home/nav.html',
authenticate: true
})
.state('home.index', { // our home page
url: '/index',
views: {
"": {templateUrl: 'templates/home/home.html'},
"assembly#index": { templateUrl: "templates/home/assembly.html" },
"client#index": { templateUrl: "templates/home/client.html" },
"photoplan#index": { templateUrl: "templates/home/home_photoplan.html" }
},
authenticate: true
})
Here is the main routes causing problems, the home one is just a nav bar, and when you go to the home tab its supposed to take you to the index page, but no dice. Im not sure how much of my controller i should show, but here a small part.Its the parts that directly effect the routes.
app.run(function ($rootScope,$location, $localStorage){
$localStorage.recent = ""
$rootScope.$on('$routeChangeSuccess', function() {
console.log("working")
recent.push($location.$$path);
});
});
app.run(function ($rootScope, $state, AuthService) {
$rootScope.$on("$stateChangeStart", function(event, toState, toParams, fromState, fromParams){
if (toState.authenticate && !AuthService.isAuthenticated()){
// User isn’t authenticated
console.log(AuthService.isAuthenticated())
$state.transitionTo("login");
event.preventDefault();
}
});
});
// GET request Area
$http.get('client.JSON').success(function(data){
$scope.clients = data;
});
$http.get('photoplan.JSON').success(function(data){
$scope.photoplans = data;
$scope.complete = true;
// if(main.photoplans.plano_order_status === "Complete"){
// console.log()
// $scope.complete = true;
// }else{
// $scope.complete = false;
// }
});
$http.get('assembly.JSON').success(function(data){
// main.assemblys = $filter('filter')(data, function(d){return d.employee_id == mainid});
$scope.assemblys = data;
console.log($scope.assemblys)
});
$http.get('employee.JSON').success(function(data){
$scope.employees = data;
});
}]);
This is the index page, and one of the nested views it has, all the views look roughly the same.
<div class="container" ng-controller="MainCtrl">
<!-- Main Section -->
<div class="home no-subheader container">
<div class="row" >
<!-- left -->
<section name="assembly-queue" class="molding col-md-4" id="assembly">
<div class="gutter" >
<div ui-view="assembly"> </div>
</div>
</section>
<!-- <section name="employee-queue" ng-if="type === 'admin'" class="molding col-md-4" id="employee">
<div class="gutter" id="scrollArea">
<div ui-view=".employee"></div>
</div>
</section> -->
<!-- middle -->
<section name="clients" class="molding col-md-4" id="clients">
<div class="gutter" >
<div ui-view="client"> </div>
</div>
</section>
<!-- right -->
<section name="photoplans" class="molding col-md-4" id="photoplans">
<div class="gutter" >
<div ui-view="photoplan"> </div>
</div>
</section>
</div>
</div>
</div>
This is the assembly page.
<div id="expanding" >
<div class="top row">
<h2> Assembly Queue</h2>
<form class="navbar-form navbar-left default" role="search">
<div class="form-group">
<input type="text" ng-model="searchassembly" class="form-control query" placeholder="Search Assembly Queue">
</div>
</form>
</div>
</div>
<article class="assembly snippet row" ng-repeat="assembly in assemblys|filter:searchassembly" >
<div class="left col-xs-7" >
<address>{{assembly.address_part1}},{{assembly.address_part2}}</address>
<p class="timeline-data"> Due on {{assembly.date_due}}</p>
<p class="timeline-data"> Job Type: {{assembly.job_type}}</p>
<p class="timeline-data"> Delivery Type: {{assembly.delivery_type}}</p>
</div>
<div class="right col-xs-5 text-center">
<div class="corner-ribbon" ng-click="open(assembly.id)" > </div>
<button ng-if="assembly.new_order" class="btn btn-default" ui-sref="photoplans({ id : assembly.photoplan_id })" ><span class="fa fa-pencil-square-o" aria-hidden="true"></span></button>
<button ng-if="assembly.new_order === false" class="btn btn-default" ui-sref="assign({address : assembly.address, realtor: assembly.realtor})" ><span class="fa fa-external-link" aria-hidden="true"></span></button>
</div>
</article>
If anyone has had similar issues or can see red flags in this please let me know, i am really stuck on this issue.
Okay so i actually found the answer myself, and im leaving the solution here for future people who might have this issue. But basically i need to have word of some kind in my home route, so instead of just /, i need /home. Because the browser was trying to load this #//index, and that was causing crashes. When using rails and angular together, make sure to have named routes to prevent this problem. Also make sure your nested views look like this, whatever#parent.child. Heres my new code.
planoxApp.config(['$stateProvider','$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'templates/home/nav.html',
authenticate: true
})
.state('home.index', { // our home page
url: '/index',
views: {
"": {templateUrl: 'templates/home/home.html'},
"assembly#home.index": { templateUrl: "templates/home/assembly.html" },
"client#home.index": { templateUrl: "templates/home/client.html" },
"photoplan#home.index": { templateUrl: "templates/home/home_photoplan.html" }
},
authenticate: true
})

Resources