本文介绍了如何将@Model 传递给 Angular ng-init的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 ASP.NET MVC 4 视图中不能将 @Model 传递给 ng-init
吗?当我像 data-ng-init=init(@Model)
那样做时,它在 init()
函数中是未定义的.
Isn't it possible to pass @Model to ng-init
in ASP.NET MVC 4 view? When I do it like data-ng-init=init(@Model)
it is undefined in the init()
function.
$scope.init = fuynction(model){
console.log(model); // prints undefined
}
顺便说一下,我是 AngularJs 的新手.提前感谢任何帮助.
By the way I'm new to AngularJs. Any help is appreciated in advance.
推荐答案
使用 Newtonsoft.Json 程序集或类似程序将您的模型序列化为 json 字符串,并将序列化结果传递给 data-ng-init.
Serialize you model into json string, using Newtonsoft.Json assembly or similar and pass the serialization result to data-ng-init.
这篇关于如何将@Model 传递给 Angular ng-init的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!