├── README.md
├── province.js
├── city.js
├── country.js
├── http.server.ts
├── three-link.component.html
├── add_user_info.js
├── three-link.component.ts
├── username.component.html
└── username.component.ts
/README.md:
--------------------------------------------------------------------------------
1 | # ng2-output-sanjiliandong
2 | angular2三级联动,定义省市县三级联动组件,在需要的地方调用即可,使用@Output父组件获取子组件的值
3 |
--------------------------------------------------------------------------------
/province.js:
--------------------------------------------------------------------------------
1 | var express = require("express");
2 | var router = express.Router();
3 | var connection = require("../conf/db");
4 |
5 | router.get("/", function (req, res, next) {
6 | connection("select * from province", function (err, rows, fields) {
7 | console.log(rows);
8 | res.jsonp(rows);
9 | })
10 | });
11 | module.exports = router;
--------------------------------------------------------------------------------
/city.js:
--------------------------------------------------------------------------------
1 | var express = require("express");
2 | var router = express.Router();
3 | var connection = require("../conf/db");
4 |
5 | router.get("/", function (req, res, next) {
6 | var proId = req.query.ProID;
7 | connection("select * from city where ProID='" + proId + "'", function (err, rows, fields) {
8 | console.log(rows);
9 | res.jsonp(rows);
10 | })
11 | });
12 | module.exports = router;
--------------------------------------------------------------------------------
/country.js:
--------------------------------------------------------------------------------
1 | var express = require("express");
2 | var router = express.Router();
3 | var connecion = require("../conf/db");
4 |
5 | router.get("/", function (req, res, next) {
6 | var CityID = req.query.CityID;
7 | connecion("select * from country where CityID = '" + CityID + "'", function (err, rows, fields) {
8 | console.log(rows);
9 | res.jsonp(rows);
10 | })
11 | });
12 |
13 | module.exports = router;
--------------------------------------------------------------------------------
/http.server.ts:
--------------------------------------------------------------------------------
1 | import {Injectable} from "@angular/core";
2 | import {Http, Jsonp} from "@angular/http";
3 | import "rxjs/add/operator/map";
4 | @Injectable()
5 | export class HttpServer {
6 | constructor(public http:Http, public jsonp:Jsonp) {
7 |
8 | }
9 |
10 | httpGet(url, params) {
11 | return this.http.get(url, {search: params}).map(result=>result.json());
12 | }
13 |
14 | httpPost(url, params) {
15 | return this.http.post(url, {search: params}).map(result=>result.json());
16 | }
17 |
18 | jsonpGet(url, params) {
19 | return this.jsonp.get(url, {search: params}).map(result=>result.json());
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/three-link.component.html:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
12 |
13 |
14 |
18 |
19 |
--------------------------------------------------------------------------------
/add_user_info.js:
--------------------------------------------------------------------------------
1 | var express = require("express");
2 | var router = express.Router();
3 | // 数据库
4 | var connection = require("../conf/db");
5 | router.get("/", function (req, res, next) {
6 | var username = req.query.username;
7 | var sex = req.query.sex;
8 | var age = req.query.age;
9 | var address = req.query.address;
10 | var position = req.query.position;
11 | var hobby = req.query.hobby;
12 | var remark = req.query.remark;
13 | var province = req.query.province;
14 | var city = req.query.city;
15 | var country = req.query.country;
16 |
17 | connection("update users set province='" + province + "', city='" + city + "', country='" + country + "', sex='" + sex + "', age='" + age + "', address='" + address + "', position='" + position + "', hobby='" + hobby + "', remark='" + remark + "' where username='" + username + "'", function (err, rows, field) {
18 | console.log(rows);
19 | res.jsonp(rows);
20 | })
21 |
22 | });
23 | module.exports = router;
--------------------------------------------------------------------------------
/three-link.component.ts:
--------------------------------------------------------------------------------
1 | import {Component, OnInit, Output, EventEmitter} from "@angular/core";
2 | import {URLSearchParams} from "@angular/http";
3 | import {HttpServer} from "../servers/http.server";
4 | @Component({
5 | selector: "three-link",
6 | templateUrl: "../templates/three-link.component.html"
7 | })
8 | export class ThreeLinkComponent implements OnInit {
9 |
10 | // 输出一下参数
11 | @Output() provinceOut = new EventEmitter();
12 | @Output() cityOut = new EventEmitter();
13 | @Output() countryOut = new EventEmitter();
14 |
15 | province:string;
16 | city:string;
17 | country:string;
18 | provinceData:Array