簡體   English   中英

如何從spring控制器獲取angularjs中的模型屬性值

[英]how to get model attribute value in angularjs from spring controller

我將彈簧控制器定義為

@Controller
public class TestController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @RequestMapping(value="/hello")
    public String home(HttpServletRequest httpRequest, Model model) {        

            model.addAttribute("Authorization", "test string");

            return "/index";
    }  
}

有沒有辦法在angularjs控制器中獲得屬性“授權”?

嘗試這個:

($location.search()).Authorization

有關$location和參數的更多詳細信息: https//docs.angularjs.org/api/ng/service/ $ location

在控制器$ scope.var中嘗試ng-init =“var = $ {Authorization}”

我遇到了同樣的問題,但是($location.search()).attributeKey對我不起作用。 在我的angularJs控制器中,我通過($location.search()).attributeKey接收'未定義'值。

我有這個問題已經有一段時間了。 我使用'hackish'方式來訪問在后端添加為模態屬性的變量。

假設您已將"some-data"添加到模型中,如下所示。

model.addAttribute("some-data-id", "some-data");

在ctrl初始化的jsp中,將屬性添加到隱藏的html元素(如span)

<span style="display:none" id="someDataId">${some-data-id}</span>

在控制器中,使用angular.element('#some-data-id').innerHTML檢索值

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM