我需要将一个属性从我的组件传递给RouteData类。
@Component({
selector: 'profile',
templateUrl: 'profile.html',
})
@RouteConfig([
{path:'/posts', name: 'ProfilePosts', component: ProfileTracksComponent, data: {user}, useAsDefault: true}
])
export class ProfileComponent implements OnInit {
user = {...}
我正在尝试将user
属性放入RouteData(请参阅RouteConfig中的data
属性),但angular2表示未定义用户。 this.user
也不起作用。
我该怎么做?
答案 0 :(得分:0)
您无法从应用于该类的装饰器中引用组件实例
您可以使用共享服务注入Router并调用其中一个class CDealDataSent extends AsyncTask<String, Void, String> {
public CDealAppDatastorage item;
@Override
protected void onPreExecute() {
super.onPreExecute();
m_ProgressView.setVisibility(View.VISIBLE);
}
@Override
protected String doInBackground(String... urls) {
return DealListing(urls[0]);// sending data to server...
}
// onPostExecute displays the results of the AsyncTask.
@SuppressWarnings("deprecation")
@SuppressLint("SetTextI18n")
@Override
protected void onPostExecute(final String result) {
m_ProgressView.setVisibility(View.GONE);
try {
m_oResponseobject = new JSONObject(result);// getting response from server
JSONArray posts = m_oResponseobject.optJSONArray("dealList");
for (int i = 0; i < posts.length(); i++) {
JSONObject post = posts.getJSONObject(i);
item = new CDealAppDatastorage();
item.setM_szHeaderText(post.getString("dealname"));
item.setM_szsubHeaderText(post.getString("dealcode"));
item.setM_szDealValue(post.getString("dealvalue"));
item.setM_n_Image(m_n_FormImage[i]);
s_oDataset.add(item);
}
// LoadMore button
Button btnLoadMore = new Button(getActivity());
btnLoadMore.setText("LOAD MORE DEALS");
btnLoadMore.setBackgroundResource(R.drawable.button_boarder);
btnLoadMore.setTextAppearance(getActivity(), android.R.style.TextAppearance_DeviceDefault_Small);
btnLoadMore.setTextColor(Color.WHITE);
btnLoadMore.setGravity(Gravity.CENTER);
if (!s_oDataset.isEmpty()) {
// Adding Load More button to lisview at bottom
m_ListView.addFooterView(btnLoadMore);
m_oAdapter = new CDealAppListingAdapter(getActivity(), s_oDataset);// create adapter object and add arraylist to adapter
m_ListView.setAdapter(m_oAdapter);//adding adapter to recyclerview
m_oAdapter.notifyDataSetChanged();
} else {
btnLoadMore.setVisibility(View.GONE);
}
btnLoadMore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
m_n_DefaultRecordCount = m_n_DefaultRecordCount + 5;// increment of record count by 5 on next load data
m_n_DeafalutLastCount = m_n_DeafalutLastCount + 5;// same here.....as above
sz_RecordCount = String.valueOf(m_n_DefaultRecordCount);// convert int value to string
sz_LastCount = String.valueOf(m_n_DeafalutLastCount);// convert int value to string /////
new DealNext().execute(m_DealListingURL);// POST DATA TO SERVER TO LOAD MORE DATA......
}
});
getResponse();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
函数来传递其他数据。