Angular无法解析模板-条件templateUrl

时间:2018-08-29 14:54:31

标签: angular typescript

public class MovieRecyclerViewAdapter extends RecyclerView
    .Adapter<MovieRecyclerViewAdapter.MovieItemViewHolder> {

public List<MovieViewModel> vmList;


public MovieRecyclerViewAdapter(List<MovieViewModel> vmList) {

    this.vmList = vmList;
    setHasStableIds(true);
}

@Override
public MovieItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    MovieView itemView = new MovieView(parent.getContext(), null);
    itemView.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT
    ));
    return new MovieItemViewHolder(itemView);
}

@Override
public void onBindViewHolder(@NonNull MovieItemViewHolder holder, int position) {


    vmList.get(position).observe(?????, users -> {

  // As you can see I have no reference to the life cycle owner
       holder.imageView.setimage(some drawable returned by the View Model)
    });
}


@Override
public long getItemId(int position) {

    return position;
}

@Override
public int getItemViewType(int position) {

    return position;
}


@Override
public int getItemCount() {

    return vmList.size();
}

class MovieItemViewHolder extends RecyclerView.ViewHolder {

    private MovieView channelView;

    public MovieItemViewHolder(View v) {

        super(v);
        channelView = (MovieView) v;
    }

    public MovieView getChannelView() {

        return channelView;
    }
 }

}

在上面,我试图编写一个名为import { Component } from '@angular/core'; import { environment } from '../environments/environment'; const template = environment.production ? '../dev/dev-app.component.html' : './app.component.html'; @Component({ selector: 'app-root', templateUrl: template, styleUrls: ['./app.component.scss'] }) export class AppComponent { title = 'app'; } 的条件变量,它将加载组件的视图。

仅出现以下错误:

  ./src/app/app.component.ts中的

错误

     

找不到模块:错误:无法解析'/ src / app'中的'模板'

1 个答案:

答案 0 :(得分:0)

我找到了本文的解决方案-Importing HTML files in TypeScript