Skip to content

Instantly share code, notes, and snippets.

@yitsushi
Created March 12, 2014 12:35
Show Gist options
  • Save yitsushi/9506058 to your computer and use it in GitHub Desktop.
Save yitsushi/9506058 to your computer and use it in GitHub Desktop.
var App = {
controllers: {},
configuration: {
domain: "s.l",
protocol: "http"
},
utils: {}
};
(function UrlUtils (app) {
app.utils.url = {
get: function(path) {
return app.configuration.protocol + "://" + app.configuration.domain + path;
}
};
})(App);
(function LinkController (app) {
app.controllers.Link = function ($scope) {
$scope.links = [];
$scope.addLink = function addLink () {
$scope.links.unshift({
short: App.utils.url.get("/a4d56g"),
long: $scope.newLink,
clicks: 0,
created_at: new Date()
});
$scope.newLink = "";
return null;
};
};
app.controllers.Link.$inject = ['$scope'];
})(App);
<html ng-app>
<head>
<link rel="stylesheet" href="stylesheets/main.css">
<script type="text/javascript" src="javascripts/angular.min.js"></script>
<script type="text/javascript" src="javascripts/app.js"></script>
</head>
<body>
<div ng-controller='App.controllers.Link'>
<form ng-submit="addLink()">
<input type="text"
ng-model="newLink"
placeholder="add new link here">
<input type="submit" value="add">
</form>
<table>
<tr>
<th>Short link</th>
<th>Target link</th>
<th>Clicks</th>
<th>Created at</th>
</tr>
<tr ng-repeat="link in links">
<td><a href="{{link.short}}">{{link.short}}</a></td>
<td><a href="{{link.long}}">{{link.long}}</a></td>
<td>{{link.clicks}}</td>
<td>{{link.created_at}}</td>
</tr>
</table>
</div>
</body>
</html>
html, body {
margin: 0;
padding: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment