Javascript 如何创建一个表,用户可以在其中更改影响AngularJS结果的值

Javascript 如何创建一个表,用户可以在其中更改影响AngularJS结果的值,javascript,html,angularjs,excel,Javascript,Html,Angularjs,Excel,我刚刚开始学习angularJS。我的老板给了我一份Excel电子表格,他想让我基本上把它放到网站上 在Excel中,可以更改电子表格中的单元格,这会影响使用公式的其他单元格 到目前为止,在我的应用程序中,我有一个表。例如: var-app1=angular.module('app1',[]); 附件1.控制器('ctrl1',功能($scope){ }); 类型 长度 宽度 地区 数量 公斤 亚麻门半小时 2040 926 1.89 1. 41.56 这是演示: 您可以从以下网站下载: 组

我刚刚开始学习angularJS。我的老板给了我一份Excel电子表格,他想让我基本上把它放到网站上

在Excel中,可以更改电子表格中的单元格,这会影响使用公式的其他单元格

到目前为止,在我的应用程序中,我有一个表。例如:

var-app1=angular.module('app1',[]);
附件1.控制器('ctrl1',功能($scope){
});

类型
长度
宽度
地区
数量
公斤
亚麻门半小时
2040
926
1.89
1.
41.56
这是演示:

您可以从以下网站下载:

组件代码:

import {Component, Input, AfterViewChecked} from '@angular/core';
import {NgModel} from '@angular/common';
import {SpreadsheetModel} from './spreadsheetModel';
import {KeyMap} from './key-map';
import {HeaderRowService} from './header-row-service';
@Component({
    selector: 'spreadsheet',
    templateUrl: './components/spreadsheet/spreadsheet.html'
})
export class Spreadsheet implements AfterViewChecked {
    model:SpreadsheetModel;
    @Input() rows:Number;
    @Input() columns:Number;
    constructor(){
        this.model = new SpreadsheetModel(10,4);
        this.header = HeaderRowService.createHeader(this.model.rows[0].columns.length);
        this.visibleRows = this.getVisibleRows();
    }
    getHeader(){
        return HeaderRowService.createHeader(this.model.rows[0].columns.length);
    }
    navigate($event){
        this.model.navigate($event.keyCode);
        this.visibleRows = this.getVisibleRows();
    }
    ngAfterViewChecked(){
        let cell = document.getElementById(this.model.current.rowIndex + '-' + this.model.current.columnIndex);
        cell.focus();
    }
    getVisibleRows(){
        return this.model.rows.filter((row) => row.rowIndex >= this.model.start && row.rowIndex < this.model.end);
    }
    getActive(col){
        if(col === this.model.current){
            return 'active-cell';
        }
    }
}
从'@angular/core'导入{组件,输入,AfterViewChecked};
从“@angular/common”导入{NgModel};
从“./SpreadsheetModel”导入{SpreadsheetModel};
从“./key-map”导入{KeyMap};
从“./头行服务”导入{HeaderRowService};
@组成部分({
选择器:“电子表格”,
templateUrl:“./components/spreadsheet/spreadsheet.html”
})
导出类电子表格实现AfterViewChecked{
模型:电子表格模型;
@Input()行:数字;
@Input()列:数字;
构造函数(){
this.model=新的电子表格模型(10,4);
this.header=HeaderRowService.createHeader(this.model.rows[0].columns.length);
this.visibleRows=this.getVisibleRows();
}
getHeader(){
返回HeaderRowService.createHeader(this.model.rows[0].columns.length);
}
导航($event){
this.model.navigate($event.keyCode);
this.visibleRows=this.getVisibleRows();
}
ngAfterViewChecked(){
让单元格=document.getElementById(this.model.current.rowIndex+'-'+this.model.current.columnIndex);
cell.focus();
}
getVisibleRows(){
返回此.model.rows.filter((row)=>row.rowIndex>=this.model.start&&row.rowIndex
模型代码

import {KeyMap} from './key-map';
import {Row} from './row';
import {Column} from './column';
export class SpreadsheetModel{
    rows:Array<Row>;
    current:Column;
    start:number;
    end:number;
    constructor(public rowCount, public columnCount){
        this.rows = [];
        this.start = 0;
        this.end = rowCount;
        for(let i = 0; i < this.rowCount; i++){
            this.rows.push(new Row(i,this.columnCount));
        }
        this.current = this.rows[0].columns[0];
    }
    selectColumn(col){
        this.current = col;
    }
    navigate(keyCode){
        const navDirection = KeyMap.getNavigationDirection(keyCode);
        if(navDirection.down){
            this.ensureRow();
            this.current = this.rows[this.current.rowIndex + 1].columns[this.current.columnIndex];
            this.adjustRowRangeDownward();
        }
        if(navDirection.up){
            if(this.current.rowIndex === 0){
                return;
            }
            this.current = this.rows[this.current.rowIndex - 1].columns[this.current.columnIndex];
            this.adjustRowRangeUpward();
        }
        if(navDirection.left){
            if(this.current.columnIndex === 0){
                return;
            }
            this.current = this.rows[this.current.rowIndex].columns[this.current.columnIndex - 1];
        }
        if(navDirection.right){
            if(this.current.columnIndex === this.columnCount - 1){
                return;
            }
            this.current = this.rows[this.current.rowIndex].columns[this.current.columnIndex + 1];
        }
    }
    adjustRowRangeUpward(){
        if(this.current.rowIndex < this.start){
            this.shiftRowsBy(-1);
        }
    }
    adjustRowRangeDownward(){
        if(this.current.rowIndex === this.end){
            this.shiftRowsBy(1);
        }
    }
    shiftRowsBy(offset){
        this.start = this.start + offset;
        this.end = this.end + offset;
    }
    ensureRow(){
        if(this.current.rowIndex + 1 >= this.rows.length){
            this.rows.push(new Row(this.current.rowIndex + 1,this.columnCount));
        }
    }
}
从“/key-map”导入{KeyMap};
从“./Row”导入{Row};
从“./Column”导入{Column};
导出类电子表格模型{
行:数组;
当前:列;
开始:编号;
完:编号;;
构造函数(公共行计数、公共列计数){
this.rows=[];
这个.start=0;
this.end=行计数;
for(设i=0;i=this.rows.length){
this.rows.push(新行(this.current.rowIndex+1,this.columnCount));
}
}
}
实体

import {Column} from './column';
//Row
export class Row{
    columns:Array;
    constructor(public rowIndex, public columnCount){
        this.columns = [];
        for(let j = 0; j < this.columnCount; j++){
            this.columns.push(new Column(j,this.rowIndex));
        }
    }
}

//Column
export class Column{
    cellValue:String;
    constructor(public columnIndex,public rowIndex){
        this.cellValue = '';
    }
}
从“/Column”导入{Column};
//划船
导出类行{
列:数组;
构造函数(公共行索引、公共列计数){
this.columns=[];
for(设j=0;j
视图(模板代码HTML):


{{columnHeader}}
{{row.rowIndex}}
希望它能帮助你。我从这里复制这是演示:

您可以从以下网站下载:

组件代码:

import {Component, Input, AfterViewChecked} from '@angular/core';
import {NgModel} from '@angular/common';
import {SpreadsheetModel} from './spreadsheetModel';
import {KeyMap} from './key-map';
import {HeaderRowService} from './header-row-service';
@Component({
    selector: 'spreadsheet',
    templateUrl: './components/spreadsheet/spreadsheet.html'
})
export class Spreadsheet implements AfterViewChecked {
    model:SpreadsheetModel;
    @Input() rows:Number;
    @Input() columns:Number;
    constructor(){
        this.model = new SpreadsheetModel(10,4);
        this.header = HeaderRowService.createHeader(this.model.rows[0].columns.length);
        this.visibleRows = this.getVisibleRows();
    }
    getHeader(){
        return HeaderRowService.createHeader(this.model.rows[0].columns.length);
    }
    navigate($event){
        this.model.navigate($event.keyCode);
        this.visibleRows = this.getVisibleRows();
    }
    ngAfterViewChecked(){
        let cell = document.getElementById(this.model.current.rowIndex + '-' + this.model.current.columnIndex);
        cell.focus();
    }
    getVisibleRows(){
        return this.model.rows.filter((row) => row.rowIndex >= this.model.start && row.rowIndex < this.model.end);
    }
    getActive(col){
        if(col === this.model.current){
            return 'active-cell';
        }
    }
}
从'@angular/core'导入{组件,输入,AfterViewChecked};
从“@angular/common”导入{NgModel};
从“./SpreadsheetModel”导入{SpreadsheetModel};
从“./key-map”导入{KeyMap};
从“./头行服务”导入{HeaderRowService};
@组成部分({
选择器:“电子表格”,
templateUrl:“./components/spreadsheet/spreadsheet.html”
})
导出类电子表格实现AfterViewChecked{
模型:电子表格模型;
@Input()行:数字;
@Input()列:数字;
构造函数(){
this.model=新的电子表格模型(10,4);
this.header=HeaderRowService.createHeader(this.model.rows[0
<td><super-edit value="2040"></super-edit></td>
    <tbody>
      <tr>
        <td>Flax Door Half Hour</td>
        <td><super-edit value="2040"></super-edit></td>
        <td><super-edit value="926"></super-edit></td>
        <td><super-edit value="1.89"></super-edit></td>
        <td><super-edit value="1"></super-edit></td>
        <td><super-edit value="41.56"></super-edit></td>
      </tr>
    </tbody>

function superEdit() {
    return {
    scope: {},
    restrict: 'E',
    bindToController: {
        value: '='
    },
    template: [
      '<span ng-if="!c.editMode" ng-click="c.editMode = true">{{c.value}}</span>',
      '<input type="text" ng-model="c.value" ng-if="c.editMode" ng-blur="c.editMode = false">'
    ].join(''),
    controller: SuperController,
    controllerAs: 'c'
  }
}
function SuperController() {
    this.editMode = false;
}
angular.module('myApp', []);
angular
    .module('myApp')
    .directive('superEdit', superEdit);