javascript - AngularJS从 Controller 注入(inject)部分 View

标签 javascript jquery asp.net-mvc angularjs

在 angularjs 应用程序 View 页面内,我有类似的无序列表

<ul>
   <li> Item 1 </li>
   <li> Item 2 </li>
   <li> Item 3 </li>
</ul>

在同一页面上,我有占位符,我想在其中加载带有从 Controller 返回的内容的部分 View

<div id="partialResults">
</div>

我正在考虑 onclick 每个 itemam 调用 Controller 函数,然后将部分 View 从 Controller 返回到 View 。

我怎样才能在 angularjs 中做到这一点,或者对于这种情况有更好的方法。这样我会在 asp.net-mvc 中发送 ajax 请求并从 Controller 返回部分 View 。

最佳答案

像这样的东西应该可以工作。使用您想要包含的 HTML View 调用 Controller 中的函数:

<li ng-click='loadPartial("item1.html")'> Item 1 </li>

然后在 Controller 中将其设置为事件变量:

$scope.loadPartial = function(link) {
    $scope.currentPartial = $scope.basePath + link;
}

然后在div中:

<div id="partialResults" ng-include="currentPartial">
</div>

关于javascript - AngularJS从 Controller 注入(inject)部分 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30931914/

相关文章:

javascript - 作者说的 "event handler function wants to unbind itself after it fires"是什么意思

javascript - 如何解决 Angular js 中的 json 解析问题

javascript - 如何将标记悬停在 MarkerWithLabel Google map 上

javascript - JQuery 在 if/else 中设置变量的问题

c# - 从数据库更新 Entity Framework 模型,无法识别自定义属性

c# - NullReferenceException 在 ASP.NET MVC 5 中使用 DropDownListFor

javascript - Node.js 中调用 Object.create(new EventEmitter) 是什么意思

javascript - 在javascript中解析具有未知字段名称的json数组

javascript - JQUERY Ajax Get方法获取数据属性

ASP.NET MVC 在安全内容和非安全内容之间切换