Skip to content

Instantly share code, notes, and snippets.

@soy-curd
Created May 20, 2016 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save soy-curd/9190c930fd07c744fbd0f224565c97f1 to your computer and use it in GitHub Desktop.
Save soy-curd/9190c930fd07c744fbd0f224565c97f1 to your computer and use it in GitHub Desktop.
angular1x_typescript_snipet
var MyService = function (a, b) {
console.log(a);
return a + b;
};
var MyController = function ($scope, addService) { // 自動で名前解決する
$scope.message = "Hello world";
$scope.action = function ($event) {
if ($scope.message.indexOf("o") > 0) {
$scope.message = $scope.message.slice(0, -1);
} else {
$scope.message = "GooooooooodBye!";
}
$scope.hoge = addService(10, 20);
$event.stopPropagation();
console.log($event);
};
};
var appModule = angular.module("app", []);
appModule.value("addService", MyService)
appModule.controller("MyController", MyController);
<!doctype html>
<html ng-app="app">
<head>
<script src="angular.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<div>
<label>Name:</label>
<input type="text" ng-model="yourName" placeholder="Enter a name here">
<hr>
<h1>Hello {{yourName}}!</h1>
<p>{{1 + 1}}</p>
<div ng-init="variables=[1, 2, 3]" ng-if="yourName">
<li ng-repeat="variable in variables">
<p>{{variable}}</p>
</li>
</div>
<input type="text" ng-model="hoge" placeholder="Enter a name here">
<hr>
<h1>Hello {{hoge}}!</h1>
</div>
<div ng-controller="MyController">
<div ng-cloak>
{{message}}
{{hoge}}
<p ng-bind="hoge"></p>
</div>
<button ng-click="action($event)">push</button>
</div>
<input type="checkbox" ng-model="check">
<div ng-if="check">
ふが
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment