Skip to content

Instantly share code, notes, and snippets.

@nonZero
Created June 21, 2016 09:46
Show Gist options
  • Save nonZero/74922747cb52857c525159c9e53c1a9e to your computer and use it in GitHub Desktop.
Save nonZero/74922747cb52857c525159c9e53c1a9e to your computer and use it in GitHub Desktop.
angular controllers
"use strict";
console.log("app starts");
var mymod = angular.module("mymodule", []);
mymod.run(function udi($rootScope) {
console.log("mymod is loading!!!");
$rootScope.x = "ROOT!";
});
mymod.controller("CalcController", function CalcController($scope) {
console.log("calc controller");
$scope.board = [
[{mine: true}, {mine: false}, {mine: false}, {mine: false}, {mine: false}, {mine: false}],
[{mine: true}, {mine: false}, {mine: false}, {mine: false}, {mine: false}, {mine: false}],
[{mine: true}, {mine: false}, {mine: false}, {mine: false}, {mine: false}, {mine: false}],
[{mine: true}, {mine: false}, {mine: false}, {mine: false}, {mine: false}, {mine: false}],
];
});
mymod.controller("CounterController", function CounterController($scope) {
console.log("counter controller");
$scope.x = 100;
$scope.inc = function () {
$scope.x++;
};
$scope.dec = function () {
$scope.x--;
};
});
// // INSTEAD of ng-app:
// angular.element(document).ready(function() {
// console.log("ready");
// angular.bootstrap(document, ['mymodule']);
// });
console.log("app ends");
<!DOCTYPE html>
<html lang="en" ng-app="mymodule">
<head>
<meta charset="UTF-8">
<title>Super Angular!!!</title>
<link rel="stylesheet" href="bootstrap/css/bootstrap.css">
<style>
.ng-cloak {
display: none;
}
.ng-scope {
border: 1px solid red;
}
</style>
</head>
<body>
<div ng-if="false">
LOADING....
</div>
<div id="foo" class="container ng-cloak">
<div>
{{ x }}
</div>
<div>
{{ x }}
</div>
<div ng-controller="CalcController">
<p ng-repeat="row in board">
<span ng-repeat="cell in row">{{cell.mine}}</span>
</p>
</div>
<div ng-controller="CounterController">
{{ x }} <button ng-click="inc()">+</button>
</div>
<div ng-controller="CounterController">
{{ x }} <button ng-click="dec()">-</button>
</div>
<div>
{{ x }}
</div>
</div>
<script src="angular.js"></script>
<script src="app.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment