一、Create a project process:

1.use Angular CLI to create an Angular Project "demo":

need the commmand of "ng new demo" to produce demo project.

2.load the project to VSCode

click the File,select "Open Folder"

select import project "demo"

3.Configuration and install plugins in “demo” project

Use “npm install bootstrap@3” command to produce bootstrap@3.3.7(node_modules)

Use “npm install jquery” command to produce jquery(node_modules)

Use “npm install angular-in-memory-web-api” command to intall angular-in-memory-web-api

Use “npm install select2” command to install “select2”(node_modules)

E.g: install select2:

4. In the assets directory,add css, img, js three documents, the contents of the three documents are as follows:

5.Configuration angular-cli.json

Import:

1. "styles": [

"../node_modules/bootstrap/dist/css/bootstrap.min.css",

"../node_modules/select2/dist/css/select2.min.css",

]

2. "scripts": [

"../node_modules/jquery/dist/jquery.min.js",

"../node_modules/bootstrap/dist/js/bootstrap.min.js",

"../node_modules/select2/dist/js/select2.min.js",

]

6.Startup project

input the command "npm start" to startup project.

二、Define UI Interface and decorate UI Interface

1.Define UI interface in app.component.html:

2.In assets directory, css file into a “landing.css style”, img file into the relevant pictures, js file into a “landingLoadingScript.js” script. These things are used to decorate UI inferface.

3.Configuration angular-cli.json:

Import:

"styles": [

"assets/css/landing.css"  ]

"scripts": [

"assets/js/landingLoadingScript.js" ]

4.Show UI inferface:

三、Get data from a mock server, the in-memory web API.

1. Define a class

1.new a file that name is “option.ts”.

2.In “options.ts”, define a class “Option”

3.Import InMemoryWebApiModule and add it to the module's imports array and Import HttpClientModule and add it to the module's imports array.

4.The forRoot () configuration method requires an instance of the InMemoryDataService class to populate the in-memory database with data.so,we need to define a InMemoryDataService class to initialize the data.

5.Get data from web api in app.component.ts:

(1) Import { Option } from ‘./option’ and import { HttpClient } from ‘@angular/common/http’ and import { OnInit } from ‘@angular/core’.

(2) Constructs an httpClient object:

(3) AppComponent need to implement the angular ngOnInit lifecycle hook and implement “ngOnInit()” method. We've written a logical “ngOnInit” method with fetch data. Angular will call it at the right time. We get the data from the emulation server by calling getHeroes (),and through the get () method to send the request and through subscribe() method to get the data to the parameters “options”.

(4) Bind data to app.component.html with the options data in app.component.ts:use * ngFor to loop through the data in options:

(4) Save, the browser will automatically refresh (provided you have executed the npm start command),The results shown:

angular2 + bootstrap +jquery 实例的更多相关文章

  1. Bootstrap历练实例:轮播(carousel)

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  2. Bootstrap历练实例:响应式导航(带有表单)

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  3. Bootstrap历练实例:响应式导航

    <!DOCTYPE html><html lang="zh-cn"><head><meta http-equiv="Conten ...

  4. Bootstrap 历练实例-轮播(carousel)插件的事件

    事件 下表列出了轮播(Carousel)插件中要用到的事件.这些事件可在函数中当钩子使用. 事件 描述 实例 slide.bs.carousel 当调用 slide 实例方法时立即触发该事件. $(' ...

  5. Bootstrap 历练实例-轮播(carousel)插件方法

    方法 下面是一些轮播(Carousel)插件中有用的方法: 方法 描述 实例 .carousel(options) 初始化轮播为可选的 options 对象,并开始循环项目. $('#identifi ...

  6. Bootstrap 历练实例 - 折叠(Collapse)插件事件

    事件 下表列出了折叠(Collapse)插件中要用到的事件.这些事件可在函数中当钩子使用. 事件 描述 实例 show.bs.collapse 在调用 show 方法后触发该事件. $('#ident ...

  7. Bootstrap 历练实例 - 折叠(Collapse)插件方法

    方法 下面是一些折叠(Collapse)插件中有用的方法: 方法 描述 实例 Options:.collapse(options) 激活内容为可折叠元素.接受一个可选的 options 对象. $(' ...

  8. Bootstrap历练实例:简单的可折叠

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...

  9. Bootstrap 历练实例 - 按钮(Button)插件复选框

    复选框(Checkbox) 您可以创建复选框按钮 组,并通过向 btn-group 添加 data 属性 data-toggle="buttons" 来添加复选框按钮组的切换. & ...

随机推荐

  1. XEP-0199 XMPP Ping

    原文来自:https://xmpp.org/extensions/xep-0199.html,只翻译了技术方面的内容. 摘要:这个规范定义了一个通过XML流发送应用级别pings的XMPP扩展协议.这 ...

  2. vue2.x学习笔记(二十八)

    接着前面的内容:https://www.cnblogs.com/yanggb/p/12682573.html. 生产环境部署 以下大多数内容在你使用vue cli的时候都是默认开启的,仅跟你自定义的构 ...

  3. P1518 两只塔姆沃斯牛 The Tamworth Two(简单的搜索题)

    题目描述 两只牛逃跑到了森林里.农夫John开始用他的专家技术追捕这两头牛.你的任务是模拟他们的行为(牛和John). 追击在10x10的平面网格内进行.一个格子可以是: 一个障碍物, 两头牛(它们总 ...

  4. 2019 ICPC 银川网络赛 F-Moving On (卡Cache)

    Firdaws and Fatinah are living in a country with nn cities, numbered from 11 to nn. Each city has a ...

  5. select函数的使用

    select函数是 I/O 复用中非常重要的一个函数,属于并发编程的.它能够监视我们需要监视的文件描述符的变化情况–读.写或者异常 1. 函数原型 #include <sys/select.h& ...

  6. 题目分享L

    题意:n个人围成一个环,每个人初始有一些金币,每个人可以把金币递给相邻的人,问最少传递多少金币使每个人金币数相同? 分析:首先在保证最优的情况下不可能会出现相邻的两个人互相送金币,因为这样他们公共的部 ...

  7. centos7 安装高版本svn

    一.安装高版本svn 1.创建一个新的yum库文件,vim /etc/yum.repos.d/wandisco-svn.repo 内容如下 [WandiscoSVN] name=Wandisco SV ...

  8. F - Power Network POJ - 1459

    题目链接:https://vjudge.net/contest/299467#problem/F 这个是一个很简单的题目,但是读入很有意思,通过这个题目,我学会了一种新的读入方式. 一个旧的是(%d, ...

  9. WCF学习(二)

    WCF通道模型 绑定的本质是一个配置好的通道栈,为了方便程序员专著与业务逻辑,WCF提高了一系列常用绑定.随后会有相应的自定义通道栈代码 无论交互的另一方具体位置在哪里,WCF都会为消息的发送和接收建 ...

  10. (三)Redis &分布式锁

    1 Redis使用中的常见问题和解决办法 1.1 缓存穿透 定义:缓存系统都是按照key去缓存查询,如果不存在对应的value,就应该去DB查找.一些恶意的请求会故意查询不存在的key,请求量很大,就 ...