Thursday, February 05, 2015

Angular JS: starting out

basic hello world

HTML: 

<html data-ng-app="demoApp" >
    <head>
        <title>Angular Demo</title>
    </head>
    <body data-ng-controller="MyController">
        <h1>Hello Angular</h1>
        <input type="text" ng-model="name"/> {{name}}
        <div>
            {{age}}
        </div>
        
        <script src="angular.min.js"></script>
        <script src="test01.js"></script>
    </body>
</html>

JS:

var demoApp = angular.module('demoApp', [ ]);
demoApp.controller('MyController', function($scope){
    console.log("MyController");
    $scope.hello = "Hello from AngJS";
    $scope.customers = ["dave", "larry"];
    $scope.age = 20;
    
    $scope.myMethod = function(special){
        console.log("myMethod called: " + special);
        $scope.message = special;
    };
});

No comments: