在Web和Mobile(NativeScript)之间共享代码时,没有提供Http错误的提供程序

时间:2017-11-23 11:32:47

标签: angular typescript nativescript

我尝试使用Angular 4和NativeScript创建一个带有单个代码库的项目,如this article中所述。

我的目录结构看起来像这样。

project    
└───nativescript
└───node_modules
└───web 
│   └───src
|       └───app
|           └───dashboard
|               └───subcomp
│                   │   subcomp.component.ts
│                   │   subcomp.component.html
|    | package.json
|    | node_modules
└───x-shared
|   └───app
|       └───dashboard
|       |    dashboard.service.ts

在web / src / app中有一个x-shared符号链接。

网/ SRC /应用/ app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import { SubComp } from './dashboard/subcomp/subcomp.component';
import { HttpModule } from "@angular/http";
import { AppRoutingModule } from './app-routing.module';

@NgModule({
  declarations: [
    AppComponent,
    DashboardComponent,
    SubComp
  ],
  imports: [
    AppRoutingModule,
    BrowserModule,
    HttpModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

网/ SRC /应用/仪表板/ subcomp.component.ts

import { Component, OnInit } from '@angular/core';
import { DashboardService } from "../../x-shared/app/dashboard/dashboard.service";

@Component({
  selector: 'sub-comp',
  templateUrl: './sub-comp.component.html',
  styleUrls: ['./sub-comp.component.css'],
  providers: [DashboardService]
})
export class SubComp implements OnInit {
  constructor(private dashboardService: DashboardService ) { }
  ngOnInit() {
    // call a method in dashboardService that makes a http call
  });
 }
}

如果在web / src / app中有一个名为x-shared的实际目录,那么Web版本将正常运行。但是,它会给出错误

  

未捕获(承诺):错误:没有Http的提供者!

当它是符号链接时。

1 个答案:

答案 0 :(得分:0)

NativeScript使用Angular HTTP的包装器。 确保您使用的是public static int[][]lungimeDrumuri(int[][] array,int n){ int [][]newArray= new int[array.length][array.length]; // Add loops to initialize newArray to array for (int i = 0; i < array.length; i++) { for (int j = 0; j < array.length; j++) { newArray[i][j] = array[i][j]; } } for (int j = 0; j < n; j++) { // Add this loop for(int i=0;i<array.length;i++){ for(int j=0;j<array.length;j++){ int sum=0; for(int x=0;x<array.length;x++){ sum+=newArray[i][x]*array[x][j]; // Use newArray here } newArray[i][j]=sum; } } } // and this return newArray; 模块

app.module.ts

nativescript-angular/http