找不到模块:错误:无法解析'@ angular / http'?

时间:2018-12-28 12:27:19

标签: angular

String[] projection = {
                        ContactsContract.Data.MIMETYPE,
                        ContactsContract.Data.CONTACT_ID,
                        ContactsContract.Contacts.DISPLAY_NAME,
                        ContactsContract.Contacts.PHOTO_URI,
                        ContactsContract.Contacts.STARRED,
                        ContactsContract.RawContacts.ACCOUNT_TYPE,
                        ContactsContract.CommonDataKinds.Contactables.DATA,
                        ContactsContract.CommonDataKinds.Contactables.TYPE
                };



                String selection = ContactsContract.Data.MIMETYPE + " in (?, ?)" + " AND " +
                        ContactsContract.Data.HAS_PHONE_NUMBER + " = '" + 1 + "'";

                String[] selectionArgs =
                        {
                                ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE,
                                ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE,
                        };
                String sortOrder = ContactsContract.Contacts.SORT_KEY_ALTERNATIVE;



                Uri uri = null;
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
                    uri = ContactsContract.CommonDataKinds.Contactables.CONTENT_URI;
                }
                else
                {
                    uri = ContactsContract.Data.CONTENT_URI;

                }


                Cursor cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder);

                final int mimeTypeIdx = cursor.getColumnIndex(ContactsContract.Contacts.Data.MIMETYPE);
                final int idIdx = cursor.getColumnIndex(ContactsContract.Data.CONTACT_ID);
                final int nameIdx = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
                Log.e("Contacts----", "ontacts__nameIdx----" + nameIdx);
                final int dataIdx = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Contactables.DATA);
                final int typeIdx = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Contactables.TYPE);
                final int photo = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Contactables.PHOTO_URI);
                final int account_type = cursor.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE);
                sb = new StringBuilder();
                while (cursor.moveToNext()) {
                    long id = cursor.getLong(idIdx);

                    int type = cursor.getInt(typeIdx);
                    String data = cursor.getString(dataIdx);
                    String mimeType = cursor.getString(mimeTypeIdx);
                    String photo_uri = cursor.getString(photo);
                    String account_t = cursor.getString(account_type);

                    Log.e("Contacts----", "Contacts__----" + nameIdx+"---"+type+"---"+data+"----"+id);
                    if (mimeType.equals(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)) {

                        /**For email  **/
                        Log.e("Contacts----","Contacts__>>"+type+"---data---"+data+"--id--"+id);

                    } else {
                        //
                        Log.e("Contacts-----","Contacts__else>>"+type+"---data---"+data+"--id--"+id);

                    }
                }

                cursor.close();

3 个答案:

答案 0 :(得分:1)

位于AppModule根目录中

float

为您服务

import { BrowserModule }    from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';

@NgModule({
  imports: [
    BrowserModule,
    // import HttpClientModule after BrowserModule.
    HttpClientModule,
  ],
  declarations: [
    AppComponent,
  ],
  bootstrap: [ AppComponent ]
})
export class AppModule {}

在您的组件中

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable()
export class ConfigService {
    constructor(private http: HttpClient) { }

    getConfig() {
        return this.http.get(this.configUrl);
    }
}

  

https://angular.io/guide/http


答案 1 :(得分:0)

使用import { HttpClient, HttpHeaders } from '@angular/common/http';

答案 2 :(得分:0)

import { HttpModule } from '@angular/http';-不起作用

尝试以下一项-

import { HttpClientModule } from '@angular/common/http';

...
imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule
  ],
...

这对我有用。