Skip to main content

Creating Custom directives in AngularJS with Example

Directive is a unique and powerful feature available only in Angular. Directive let you invent new html syntax, specific to your application.
Directive can add:
    1. Behaviors
    2. Data binding to scope
    3. Replace or to extend the Html element

<html>
    <head>
        <title> Creating Custom directives in AngularJS </title>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular-route.min.js"></script>
    </head>
    <body ng-app="docsSimpleDirective">
        <h1>  Creating Custom directives using AngularJS </h1>
        <div ng-controller="Controller">
            <div my-customer> /* my-customer is a custom directive */ </div>
        </div>
        <script>
            angular.module('docsSimpleDirective', [])
            .controller('Controller', ['$scope', function($scope) {
                $scope.customer = {
                name: 'Naomi',
                address: '1600 Amphitheatre'
                };
            }])
            //Custom Directive
            .directive('myCustomer', function() {
              return {
                template: 'Name: {{customer.name}} Address: {{customer.address}}'
              };
            });
        </script>
    </body>
</html>

Comments

Popular posts from this blog

PG::DuplicateTable: ERROR: relation "taggings" already exists in Ruby on Rails

Error: PG::DuplicateTable: ERROR:  relation "taggings" already exists Solution : Already the table present in your database.But migration also trying to create a table in database.For this reason error occurred. So try to remove the table (taggings) from your database.   postgresql :     > DROP TABLE IF EXISTS taggings;   Rails console :     > ActiveRecord::Migration.drop_table(:taggings)

Simple Pagination in Ruby on Rails using will_paginate gem Tutorials

You should use the will_paginate gem for pagination. Steps : 1. Create new project    Develop > rails new addpagination 2. Open the gemfile inside the project folder (addpagination).Add below line in gemfile    gem 'will_paginate', '~> 3.0' 3. Enter below command in terminal and execute.    Develop > bundle install 4. Create the Database    Develop > rake db:create    5. Create the form using scaffolding    Develop > rails g scaffold post name:string city:string    6. Migrate the table    Develop > rake db:migrate    7. Now run the application    Develop > rails s   8. Check the application.Its working or not.    open browser and enter http://localhost:3000/    9. Configure the page redirection in routes.rb inside the config folder      root 'posts#index' 10. Now add t...

How to get a YouTube video thumbnail dynamically from the YouTube API using AngularJS

In this tutorial I have explain about the get YouTube thumbnail using AngularJS <html ng-app id="YoutubeApp">   <head>     <title>       How to get a YouTube video thumbnail dynamically from the YouTube API using  AngularJS Tutorials</title>     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>     <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>     <script>       function YoutubeController ($scope) {         $scope.todos = [];         $scope. addVideo = function() {           $scope.todos.push({text:$scope.todoText, done:false});           $scope.todoText = '';  ...