月度存档: 7 月 2018 - 第2页

angularjs4+(2.todolist)

1. html代码

<input type="text" [(ngModel)]="thing"/><button (click)="add()">新增</button>

<h2>待办列表</h2>
<ul>
  <li *ngFor="let item of list;let i=index" [hidden]="item.status==1">
    <button (click)="change(i,1)">标记</button>{{item.name}}<button (click)="del(i)">删除</button>
  </li>
</ul>
<br>
<hr>
<br>
<h2>已完成列表</h2>
<ul>
  <li *ngFor="let item of list;let i=index" [hidden]="item.status==0">
    <button (click)="change(i,0)">撤销标记</button>{{item.name}}<button (click)="del(i)">删除</button>
  </li>
</ul>

2. ts代码

list=[];
  thing="";
  constructor() { }

  ngOnInit() {
  }

  add(){
    var obj={"name":this.thing,"status":0};
    this.list.push(obj);
    this.thing="";
  }

  del(key){
    this.list.splice(key,1);
  }

  change(key,status){
    this.list[key].status=status;
  }

3 数据缓存,在第3节用service实现

AngularJS4+(1.base)

1 环境安装 nodejs,npm,cnpm , angular/cli

http://https://https://amyflash.com/?p=2687

2 新建项目 ng new projectname

3 新建组件 ng g component 组件目录/组件名

ps:新建组件在项目目录的src/组件目录下
ps:angularjs里面的组件相当于flash里面的movieclip
启动服务: ng serve –open
可选参数–prod –aot

4 ts文件里面给变量赋值,html里面{{var}}引用

{{title}}<br>{{msg}}<br>{{msg1}}
<br>
<div [innerHTML]="h"></div>
<br>
{{obj.name}}
title='hello,cool girl!';
  msg1:string='this is a string msg';
  msg:any;
    h="<h2>h2</h2>";
    obj={"name":"harriet"};
  constructor() { 
    this.msg='msg';
  }

5 html里面div的属性绑定

<div id="{{id}}">
ok
</div>
<div title="{{msg1}}">mouse on</div>
<div [title]="msg1">other way</div>
id='123';
msg1:string='this is a string msg';
  constructor() {
  }

6 循环展示数据

<ul>
  <li *ngFor="let item of list2;let i=index">
    {{item.name}}---{{i}}
  </li>
</ul>
list2:any[];
  constructor() { 
    this.msg='this msg is from constructor';
    this.list=[1,2,3,4];
    this.list2=[
      {"name":"n1"},
      {"name":"n2"},
      {"name":"n3"},
  ]
  }

7 嵌套循环展示数据

<ul>
  <li *ngFor="let item of list4;let i=index">
    {{item.car}}---{{i}}
    <ol>
      <li *ngFor="let item2 of item.list;let i2=index">
        {{item2.title}}---{{i2}}
      </li>
    </ol>
  </li>
</ul>
list4:any[];
  constructor() { 
    this.list4=[
    {
      "car":"baoma",
      "list":[{"title":"b1"},{"title":"b2"}]
    },
    {
      "car":"ad",
      "list":[{"title":"a1"},{"title":"a2"}]
    }
  ];
  }

8 点击get&set

<button (click)="getMsg()">getmsg</button>
<br>
{{msg}}
<br>
<button (click)="setMsg()">setmsg</button>
msg = 'for test';
  constructor() { }

  ngOnInit() {
  }

  getMsg(){
    alert(this.msg);
  }

  setMsg(){
    this.msg = "msg verify";
  }

9 显示隐藏div

ts文件里面定义 flag = true;

<div *ngIf="flag">test hide</div>
<br>
<button (click)="flag=!flag">hide&show</button>

10 双向数据绑定

1. 检查app.module.ts里面是否引入

import { FormsModule } from ‘@angular/forms’;
imports里面加上FormsModule

2.ts里面定义search=”双向绑定”;

3.html里面加上

<input type="text" [(ngModel)]="search"/>

yii2框架前后台用户认证分离

1.修改backend/config/main.php

            'user' => [
                'identityClass' => 'common\models\Adminuser',//认证类
                'enableAutoLogin' => true,
                'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
            ],
            'session' => [//不影响前端登录
                // this is the name of the session cookie used for login on the backend
                'name' => 'advanced-backend',
                'savePath'=>sys_get_temp_dir(),
            ],
            'request'=>[
                'cookieValidationKey'=>'sdfsfwef',
                'csrfParam'=>'_adminCSRF',
            ],

2 新建AdminLoginForm.php 参考LoginForm.php

3 修改backend/controllers/SiteController.php里面LoginForm替换成AdminLoginForm

4 参考User.php修改Adminuser.php,去掉状态

public static function tableName()
    {
        return '{{%adminuser}}';
    }

Angularjs2项目打包发布以及部署在Linux上

Angularjs2项目打包发布以及部署在Linux上

cd xx-project

npm install //更新依赖

ng build –prod –aot //最小化打包

把生成的dist目录拷贝到虚拟根目录即可

ubuntu上安装Angular/cli

1.卸载先前安装的Angular/cli

npm uninstall -g angular-cli
npm uninstall –save-dev angular-cli
npm uninstall -g @angular/cli

2.删除

rm /usr/bin/ng

3.卸载node.js

下载安装最新版本, 安装路径默认即可。

4. node -v npm -v 查看版本

5.用npm安装typescript和typings

npm install -g typescript typings

6.安装Angluar/cli

npm install -g @angular/cli@latest

7.检验ng 版本

ng -v

yii2 gii Forbidden (#403)解决方案

Forbidden (#403)
You are not allowed to access this page.

/opt/lampp/htdocs/amyflash/blogdemo2/vendor/yiisoft/yii2-gii# vim Module.php
public $allowedIPs = ['127.0.0.1', '::1','your ip'];

这样在 allowedIPs 数组里面的IP全部可以访问了