我有一个看起来像这样的网址
URL: '/重置/密码电子邮件=:USEREMAIL&安培; reset_token =:passwordResetToken'
但尝试使用 $ stateParams.passwordResetToken 访问返回未定义
答案 0 :(得分:0)
请你详细说明一下;在角结肠部分不需要'=:'
url:'/reset/password?email=userEmail&reset_token=passwordResetToken'
在控制器中你可以注入 $ stateParams 然后你就不会得到未定义的
答案 1 :(得分:0)
您可以使用$location服务,创建此服务以解析AngularJS中的网址。
这应该有效
$location.search() // will return {email: 'userEmail', reset_token: 'passwordResetToken'}
你也可以使用
$location.search('userEmail')
答案 2 :(得分:0)
通过查看您的网址,我认为您使用的是这样的路线:
public class WebService {
private String connectToServer(String address, String requestMethod) {
try {
URL url = new URL(address);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod(requestMethod);
return inputStreamToString(httpURLConnection.getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private String inputStreamToString(InputStream inputStream) {
StringBuilder stringBuilder = new StringBuilder();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String nextLine;
while ((nextLine = reader.readLine()) != null) {
stringBuilder.append(nextLine);
}
} catch (IOException e) {
e.printStackTrace();
}
return stringBuilder.toString();
}
line 23 : public List<FoodModel> getFoods(){ <-----------Error is here
String response = connectToServer("http://mtg1376.gigfa.com/api/food?day=All","GET");
if(response != null){
List<FoodModel> foodList = new ArrayList<);
try{
JSONObject mainObject = new JSONObject(response);
JSONArray foodArray = mainObject.getJSONArray("value");
for(int i = 0 ; i< foodArray.length();i++){
JSONObject foodObject = foodArray.getJSONObject(i);
FoodModel foodModel = new FoodModel();
foodModel.id = foodObject.getString("id");
foodModel.name = foodObject.getString("name");
foodModel.meal = foodObject.getString("meal");
foodModel.photo_id = foodObject.getString("photo_id");
foodModel.explanation = foodObject.getString("explanation");
foodModel.foodtime=foodObject.getString("foodtime");
foodList.add(foodModel);
}
return foodList;
} catch (JSONException e) {
e.printStackTrace();
}
}
return null; }
}
然后您应该使用.state('something.resetPassword', {
url: "/reset/password",
params: {
email: null,
reset_token: null
},
templateUrl: 'your_template.html'
})
作为:
$stateParams
希望这会对你有帮助!
答案 3 :(得分:0)
url:'/ reset / password?:email&amp;:reset_token&amp ;: role'解决问题