我们可以使用内联模板而不用任何类型的路由吗?

时间:2022-01-14 01:12:30

I am trying to use inline template in my application but i do not want to use any type of routing. Currently I am loading all the data at the initial stage but I want the data onclick event with the inline template.

我尝试在我的应用程序中使用内联模板,但是我不想使用任何类型的路由。目前,我正在初始阶段加载所有数据,但我希望使用内联模板加载数据onclick事件。

Because the requirement is such that on clicking of a link it will load data from 3 controller. and will do a transition. If I am using routing it is working fine but then I have to implement routing in whole application.

因为需求是这样的,在单击链接时,它将从3个控制器加载数据。并将做一个过渡。如果我使用路由,它运行良好,但我必须在整个应用程序中实现路由。

So could you please help me out to put inline template without using routing?

所以你能帮我在不使用路由的情况下放置内联模板吗?

Here is an example:-

这是一个例子:-

  <ng-view>Loading...</ng-view>
  <!-- Inline Templates (Partials) -->

  <script type=text/ng-template id=home.html>
  <!-- Home -->
    <ul>
      <li><a href="#/list">Show Items</a></li>
      <li><a href="#/settings">Settings</a></li>
    </ul>
  </script>

  <script type=text/ng-template id=list.html>
   <!-- List -->
   <p>Choose an Item</p>
   <ul>
     <li ng-repeat="item in items"><a href="#/detail/{{item.id}}">{{item.title}}</a></li>
   </ul>
  </script>

here is my angular routing:-

这是我的角路径:

angular.module('app', ['appServices'])
.config(['$routeProvider', function($routeProvider) {
    $routeProvider.
            when('/home', {templateUrl: 'home.html',   controller: HomeCtrl}).
            when('/list', {templateUrl: 'list.html',   controller: ListCtrl}).
            when('/detail/:itemId', {templateUrl: 'detail.html',   controller: DetailCtrl}).
            when('/settings', {templateUrl: 'settings.html',   controller: SettingsCtrl}).
            otherwise({redirectTo: '/home'});
}]);

I do not want to use routing, but want to load these template with click events.

我不想使用路由,但希望通过单击事件加载这些模板。

Thanks.

谢谢。

1 个解决方案

#1


2  

Sounds like maybe what you want is to use ng-include. http://www.w3schools.com/angular/angular_includes.asp https://docs.angularjs.org/api/ng/directive/ngInclude

听起来可能你想要的是使用ng-include。http://www.w3schools.com/angular/angular_includes.asp https://docs.angularjs.org/api/ng/directive/ngInclude

using this you can have inline templates on your page and map them to different controllers. ie.

使用它,您可以在页面上拥有内联模板并将它们映射到不同的控制器。ie。

<div ng-if="yourConditionHere" ng-controller="yourControllerName" ng-include="'myFile.htm'"></div>

#1


2  

Sounds like maybe what you want is to use ng-include. http://www.w3schools.com/angular/angular_includes.asp https://docs.angularjs.org/api/ng/directive/ngInclude

听起来可能你想要的是使用ng-include。http://www.w3schools.com/angular/angular_includes.asp https://docs.angularjs.org/api/ng/directive/ngInclude

using this you can have inline templates on your page and map them to different controllers. ie.

使用它,您可以在页面上拥有内联模板并将它们映射到不同的控制器。ie。

<div ng-if="yourConditionHere" ng-controller="yourControllerName" ng-include="'myFile.htm'"></div>