Share
Embed
Transcript
34 slides
-
Agenda Brief Introduction and Architecture Creating
your “hello world” application Adding a little design with bootstrap Using the common directives Creating the list application Looking at the Bigger picture -
Make sure to have bootstrap and angular libraries in
your folder before getting started – Enhancement of User Interface – The reason why we’re here :D UnderscoreJS – For data deletion purpose -
Our End-‐Goal for today: Building a single-‐paged Item List
Application… From Scratch! Nothing fancy. Everything is straightforward and plain simple -
Angular makes life easier You don’t need
to keep refreshing Rich in creating dynamic and interactive web pages http://www.9lessons.info/2011/09/submit-‐form-‐without-‐refreshing-‐page.html -
Angular also uses an an architectural pattern called MVC
(Model-‐View-‐Controller) -
Syntax Explanation angular.module(app_name,[]) – loads the ng-‐app directive
telling your running angular on the page $scope – serves as the bridge between the view and the controller; Also used to declare variables/functions. {{}} or double curly braces serves as displaying values to the view -
Recap Loaded up the angularJS library
Created the app and controller directives in the HTML Created the module and controller in a single JavaScript file $scope – acts as the object between the view and controller. Also used to create variables. -
Let’s make things a little interesting by adding
bootstrap to our website -
Let’s add a basic navbar to our site
(Just like the one below) -
Pre-‐defined class definitions from bootstrap <nav class="navbar
navbar-‐inverse navbar-‐fixed-‐ top"> -‐ Creates the fixed navbar on top <div class="container"> -‐ defines a container based on the width <div class="navbar-‐header”> <a href="#" class="navbar-‐ brand"> -‐ sets the header on the top-‐left of the nav <ul class="nav navbar-‐nav"> -‐ Creates the list of menus by using list items <li> Note: add 50 pixels to the top padding to adjust the content. -
ng-‐repeat Used to display list from arrays and
objects. Syntax is the same as using foreach() in OOP -
ng-‐model Used to get the data from input
(text, checkbox, radio buttons, etc) -
ng-‐show and ng-‐hide Used to show/hide based from
the condition. I can either be a boolean or conditional statements(e.g. IF) -
ng-‐click Used to trigger click events and make
corresponding actions based on logic -
Declaring functions in Angular Normaly in OOP, we
declare functions as… associated with the Function keyword In Angular, we define them by declaring it in the scope like this -
Navigating to items page without reload Putting
the tabs in action -
ng-‐init Used to initialize values. In OOP, this
is basically assigning values. (E.G. int a = 0, string b = “hello”, etc) Note that his will only work in a single controller if used for navigation -
Adding the table design Loading up libraries from
bootstrap <table class=“table table-‐stripped”> For now let’s add hard-‐coded data from the JavaScript to see the layout After, use ng-‐repeat to display data -
Searching from the textbox Add another textbox
which serves as your textbox and name the ng-‐model “search”. The filter keyword is used in the view to display filtered results together -
Adding items to the list Let’s create a
new button wherein it displays a new form for input Copy and paste the <thead> portion and replace the words into textbox with models corresponding to its column with an a prefix called “add”. Add also the checkbbox option default to false. Write the push function in the controller to add the data -
Deleting data To delete data, add another column
for the checkbox and makesure it has the model of checked from the JSON Add another button in which deletes all data the’s checked from the checkbox Load underscorejs for filter. This will be used to filter data easier. -
Clarifications There is a better way to implement
single page apps and it’s to use Angular Routing (Rather than using tab values). The reason we didn’t do it is it NEEDS to be run on a server (A.K.A localhost) for routings to work What we did are just the basics and the things you will be needing to get started. Going further to routes will make you crazy. -
What benefits can I gain from learning this?
Thesis? Increase your marketability Gaining Profit! -
Thanks! For the complete source code, go to this
link: https://github.com/xtianxchan/AngularJSListApp-‐ Workshop -
Follow my links too! Github: https://github.com/xtianxchan Linkedin: http://ph.linkedin.com/in/kristianguevara
Speaker Deck: https://speakerdeck.com/kristianguevara Website: http://kristianguevara.azurewebsites.com