Jelajahi Sumber

Angular project

Krabonub 6 tahun lalu
melakukan
10edd37166

+ 0 - 0
app/app.config.js


+ 1 - 0
app/app.module.js

@@ -0,0 +1 @@
+var app = angular.module('fea5', []);

+ 0 - 0
app/app.routes.js


+ 76 - 0
app/controllers/books-list.controller.js

@@ -0,0 +1,76 @@
+(function() {
+	'use strict';
+
+	app.controller('BooksList', function($scope){
+		$scope.sortField = 'title';
+		$scope.books = [
+			{
+				title: "Harry Potter",
+				author: "J. Rowling",
+				date: "1970-12-12",
+				cost: 100,
+				rate: 5,
+				id: 0
+			},
+			{
+				title: "Potter Harry",
+				author: "R. Jowling",
+				date: "9999-00-00",
+				cost: 999,
+				rate: 10000,
+				id: 1
+			},
+			{
+				title: "Oleg Kriuchov",
+				author: "O. Kriuchkov",
+				date: "1993-05-03",
+				cost: 1,
+				rate: 0,
+				id: 2
+			},
+			{
+				title: "Хитрый Владик",
+				author: "O. Kriuchkov",
+				date: "2000-02-05",
+				cost: 10,
+				rate: 10,
+				id: 3
+			},
+			{
+				title: "Front-End for Beginers",
+				author: "A-level",
+				date: "2010-10-10",
+				cost: 250,
+				rate: 100,
+				id: 4
+			},
+			{
+				title: "How to get a million Bucks",
+				author: "Unknown",
+				date: "1999-01-02",
+				cost: 1500,
+				rate: 234,
+				id: 5
+			},
+		];
+
+		$scope.deleteBook = function(id){
+			for(var i = 0; i < $scope.books.length; i++) {
+				if($scope.books[i].id == id) {
+					$scope.books.splice(i, 1);
+				}
+			}
+			
+		};
+
+		$scope.sortBy = function(par) {
+			if ($scope.sortField == par) {
+				$scope.sortField = "-"+par;
+			} else {
+				$scope.sortField = par;
+			}
+			
+		}
+
+	})
+})();

+ 40 - 0
app/controllers/main.controller.js

@@ -0,0 +1,40 @@
+(function() {
+	'use strict';
+
+	app.controller('Main', function($scope){
+		console.log('ok')
+		$scope.x = 1;
+		$scope.x = 2;
+
+		$scope.color = 'red';
+		$scope.data = ['apple','oranges', 'banana'];
+
+		$scope.sum = function() {
+			$scope.result = $scope.x + $scope.y
+		};
+		$scope.addItem = function() {
+			$scope.data.push($scope.item); 
+			$scope.item = '';
+		};
+		$scope.deleteItem = function(item){
+			$scope.data.splice(item, 1);
+		};
+
+		$scope.style = {
+			width: 100,
+			height: 100,
+			background: "red",
+			display: "inline-block"
+		};
+		$scope.changeWidth = function() {
+			$scope.style.width = $scope.width;
+		};
+		$scope.changeHeight = function() {
+			$scope.style.height = $scope.height;
+		};
+		$scope.changeColor = function() {
+			$scope.style.background = $scope.background;
+		};
+
+	})
+})();

+ 81 - 0
index.html

@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<html lang="en" ng-app="fea5">
+<head>
+	<meta charset="UTF-8">
+	<title>ANGULAr</title>
+	<link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css">
+</head>
+<body>
+	<div class="container" ng-controller="Main">
+		<div class="page-header">
+			<h1>Hello</h1>
+		</div>
+		<h2 ng-show="x>y">Go Home 1</h2>
+		<h2 ng-hide="x>y">Go Home 2</h2>
+		<h3 ng-if="true">asdfasdad</h3>
+
+		<div ng-switch="color">
+			<div ng-switch-when="red">aaaa</div>
+			<div ng-switch-when="blue">aaaa</div>
+			<div ng-switch-when="green">aaaa</div>
+			<div ng-switch-when="black">aaaa</div>
+			<div ng-switch-default="purple">aaaa</div>
+		</div>
+
+		<input type="number" ng-model="value"> + 1 = {{1+value}}
+
+		<input type="number" ng-model="x"><button ng-click="sum()">+</button><input type="number" ng-model="y"> {{result}}
+
+		<input type="text" ng-model="item">
+		<button class="btn btn-primary" ng-click="addItem()">+</button>
+		<ul>
+			<li ng-repeat="item in data track by $index">{{item}} <button class="btn btn-danger" ng-click="deleteItem($index)">x</button></li>
+		</ul>
+
+		<div>
+			<div class="col-md-6">
+				<div>Shape Maker</div>
+				<span>Width</span><input type="number" ng-model="style.width""><br />
+				<span>Height</span><input type="number" ng-model="style.height" ><br />
+				<span>Background</span><input type="text" ng-model="style.background" >
+			</div>
+			<div class="col-md-6">
+				<div ng-style="{width: style.width+'px', height: style.height+'px', background: style.background}"></div>
+			</div>
+		</div>
+	</div>
+
+	<div ng-controller="BooksList">
+
+		<div class="page-header"><h1>Books List</h1></div>
+		<div>
+			<input ng-model="searchString" placeholder="sortFieldlter">
+		</div>
+		<table class="table table-striped">
+			<thead>
+				<tr>
+					<th ng-click="sortBy('title')"><i class="glyphicon" ng-class="{'glyphicon-chevron-up': sortField === 'title', 'glyphicon-chevron-down': sortField === '-title'}">TITLE</th>
+					<th ng-click="sortBy('author')"><i class="glyphicon" ng-class="{'glyphicon-chevron-up': sortField === 'author', 'glyphicon-chevron-down': sortField === '-author'}"></i>Author</th>
+					<th ng-click="sortBy('date')">Date</th>
+					<th ng-click="sortBy('cost')">Cost</th>
+					<th ng-click="sortBy('rate')">Rate</th>
+				</tr>
+			</thead>
+			<tr ng-repeat="item in books | orderBy: sortField |filter: searchString track by $index ">
+				<td>{{item.title}}</td>
+				<td>{{item.author | uppercase}}</td>
+				<td>{{item.date | date: 'longDate'}}</td>
+				<td>{{item.cost | currency}}</td>
+				<td>{{item.rate | number : 1}}</td>
+				<td><button class="btn btn-danger" ng-click="deleteBook(item.id)">x</button></td>
+			</tr>
+		</table>
+		<div class="text-center" ng-if="!books.length">No data</div>
+	</div>
+
+	<script src="./node_modules/angular/angular.js"></script>
+	<script src="./app/app.module.js"></script>
+	<script src="./app/controllers/main.controller.js"></script>
+	<script src="./app/controllers/books-list.controller.js"></script>
+</body>
+</html>

File diff ditekan karena terlalu besar
+ 9607 - 0
package-lock.json


+ 22 - 0
package.json

@@ -0,0 +1,22 @@
+{
+  "name": "2018-06-01",
+  "version": "1.0.0",
+  "description": "",
+  "main": "webpack.config.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1",
+    "server": "webpack-dev-server --color --watch-content-base --open"
+  },
+  "author": "",
+  "license": "ISC",
+  "devDependencies": {
+    "html-webpack-plugin": "^3.2.0",
+    "webpack": "^3.12.0",
+    "webpack-cli": "^2.1.4",
+    "webpack-dev-server": "^2.11.2"
+  },
+  "dependencies": {
+    "angular": "^1.6.6",
+    "bootstrap": "^3.3.7"
+  }
+}

+ 16 - 0
webpack.config.js

@@ -0,0 +1,16 @@
+const path = require('path');
+const glob = require('glob');
+
+const config = {
+	context: path.resolve(__dirname, './'),
+	entry: {
+		app: './app/app.module.js',
+	},
+	devServer: {
+		port: 9000,
+		stats: 'errors-only'
+	}
+};
+
+module.exports = config;
+