开坑,一直喜欢口袋妖怪,想着能写点有关的程序。css
最近项目要改写管理系统,因此用Angular1.x搭建一个口袋妖怪管理系统试试。html
巩固Ng1.x的知识+学习库的用法,而后算是记录一个系统从零开始到成型的过程吧哈哈~node
暂时计划比较简单,该网站是一个SPA即单页面管理系统应用,暂时分为五个页面:webpack
在完成管理界面以后尝试设计一个主界面,相似宝可梦图鉴的页面,用来练习界面设计&展现口袋妖怪列表git
npm i -g yarn
yarn init
那咱们先来设计咱们的项目文件构成angularjs
<!DOCTYPE html> <html lang="en" ng-app="pokemon-app"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>口袋妖怪</title> <script src="libs/angular.js"></script> <script src="app.js"></script> <link rel="stylesheet" href="app.css"/> </head> <body ng-controller="AppController"> <h1>口袋妖怪管理系统</h1> <table> <tr> <th>名称</th> <th>数量</th> <th>重量</th> <th>总计</th> <th>操做</th> </tr> <tr ng-repeat="pokemon in pokemons"> <td>{{pokemon.name}}</td> <td><input type="text" ng-model="pokemon.count"></td> <td>{{pokemon.weight}}</td> <td>{{pokemon.weight * pokemon.count}}</td> <td><button ng-click="remove($index)">删除</button></td> </tr> </table> </body> </html>
- 首先将angular.js从刚才下载的包中复制黏贴工程中新建的libs文件夹下,并在html中引入 - 而后引入app.js做为主JS文件 - 在html标签中加入**ng-app="pokemon-app"**,即html中都是'pokemon-app'模块的管理区域 - 在body标签中加入**ng-controller="AppController"**,即body下都是'AppController'控制器的控制区域 - table中第二个tr使用了AngularJS1.x的语法ng-repeat,意思就是遍历pokemons并取出每一个pokemon做为列表项渲染
(function () { 'use strict'; angular.module('pokemon-app', []) .controller('AppController', AppController); var pokemons = [ {no:'001', name:'妙蛙种子', count: 1, weight: 6.9}, {no:'002', name:'妙蛙草', count: 1, weight: 13.0}, {no:'003', name:'妙蛙花', count: 1, weight: 100}, {no:'004', name:'小火龙', count: 1, weight: 8.5}, ]; AppController.$inject = ['$scope']; function AppController ($scope) { $scope.pokemons = pokemons; $scope.remove = function (index) { $scope.pokemons.splice(index, 1); } } })();
- 这里使用了'use strict'即严格模式,不作详细解释,可自信百度 - 先用**angular.module('pockmon-app', [])**声明模块,再为模块添加控制器AppController - 中间手撸了一个pokemons数据数组,在AppController中引用,并编写对象pokemons和remove方法
此时工程已经基本完成,能够双击index.html,在浏览器上应该就可以看到以下界面了~若是不行的话能够参考一下源码的第一次提交github
用如今的方法本地运行,说实话有点原始,若是我要分享给盆友看怎么办,难道整个源代码给他运行?固然不,更优雅的解决方案http-server
了解一下.web
只要在命令进入项目,输入yarn add http-server --dev
,完成安装后输入http-server
并回车,就能够简单开启本地服务器,这个时候你的盆友就能够超方便的根据地址+端口访问刚刚的做品啦(固然要让盆友先连上和电脑相同网段的WiFi啦)npm
从零开始搭建口袋妖怪管理系统(2)-借助ngRoute实现详情页面跳转json
从零开始搭建口袋妖怪管理系统(3)-实现一个简单的SPA管理系统
从零开始搭建口袋妖怪管理系统(4)-借助webpack4.6工程化项目(上)
从零开始搭建口袋妖怪管理系统(5)-借助webpack4.6工程化项目(下)
To be continue...