Now here's where you can put all of your Angular skills and data binding to work with the Angular implementation. If you're already experienced with Angular, then it's not radically different here.
- <!-- Next button -->
- <fa-modifier
- fa-origin ="origin.center"
- fa-align ="align.nextBtn"
- fa-size ="size.btn"
- fa-scale ="scale.nextBtn.get()"
- fa-translate ="trans.topLayer">
- <fa-surface
- class ="one-edge-shadow center-align next-btn"
- ng-click ="getPokemon(); nextBtnPressAnim(); frontImgAnim()">
- {{nextBtn}}
- </fa-surface>
- </fa-modifier>
I am also binding the value of $scope.nextBtn to {{nextBTn}} in HTML.
To allow Famo.us and Angular to work together, we need to include $Famo.us at the top of our JavaScript file. Here's how you do it:
- angular.module('famousAngularStarter')
- .controller('PokemonCtrl', ['$scope', '$http', '$famous', function ($scope, $http, $famous) {
- /* Inject famo.us to DOM */
- var View = $famous['famous/core/View' ];
- var Modifier = $famous['famous/core/Modifier' ];
- var Surface = $famous['famous/core/Surface' ];
- var Transform = $famous['famous/core/Transform' ];
- var Transitionable = $famous['famous/transitions/Transitionable'];
- var Timer = $famous['famous/utilities/Timer' ];
What would a high-performance app be without animations? Famo.us is packed with them, which makes it easy to get started. Here's one for animating the image on the front.
- /*
- * @OnClick: Sets the opacity and scale for the front image when user clicks "Next" btn
- * 1) Turns opacity invisible quickly before returning to original opacity, revealing new Pokemon
- * 2) Turns scale down before quickly turning it back up to original size
- */
- $scope.frontImgAnim = function() {
- var hideDuration = 200;
- var returnDuration = 1300;
- $scope.opac.imgFront. set(0, {duration: hideDuration, curve: "easeIn"},
- function returnToOrigOpacity() {
- $scope.opac.imgFront.set(1, {duration: returnDuration, curve: "easeIn"})
- }
- );
- $scope.scale.imgFront .set([0.5, 0.5], {duration: hideDuration, curve: "easeIn"},
- function returnToOrigSize() {
- $scope.scale.imgFront.set([0.8, 0.8], {duration: returnDuration, curve: "easeIn"})
- }
- )
- };
returnToOrigSize,, to have the image grow and then shrink back to the original size.Points of Frustration
I ran into a few issues along the way.
FA-Directives Have Their Properties Set as Strings
- fa-origin ="origin.center"
Adding Classes
In FA-Directives you add multiple classes as strings and they are not comma-separated.
- <fa-surface
- class ="one-edge-shadow center-align next-btn"
- ng-click ="infoBtnPressAnim(); flip()">
- {{infoBtnText}}
- </fa-surface>
- var logo = new Surface({
- properties: {
- ...
- },
- classes: ['backfaceVisibility, class-two']
- });
Famo.us + Angular Seems to Be Deprecated (For Now)
Midway through this project, I saw that Famo.us was working on an improved version of the framework that includes Mixed Mode. Famo.us + Angular doesn't take advantage of these additions (yet) at least. That doesn't mean FA is going anywhere, as it works perfectly fine—it's just that you won't be getting the latest features.
More Hands-On With JavaScript
This article is part of the web development series from Microsoft tech evangelists on practical JavaScript learning, open-source projects, and interoperability best practices, including Microsoft Edge browser and the new EdgeHTML rendering engine.
We encourage you to test across browsers and devices including Microsoft Edge—the default browser for Windows 10—with free tools on dev.modern.IE:
Scan your site for out-of-date libraries, layout issues, and accessibility
Use virtual machines for Mac, Linux, and Windows
Remotely test for Microsoft Edge on your own device
Coding Lab on GitHub: Cross-browser testing and best practices
Written by David Voyles
If you found this post interesting, follow and support us.
Suggest for you:
Learn Angular 2 Development By Building 10 Apps
No comments:
Post a Comment