用AngularJS加载局部
Loading Partials with AngularJS
我想加载我的部分时需要吗?例如,我有一个部分,其中包括6个缩略图,当点击一个它加载我的部分,请让我知道?
您需要使用路由来做到这一点。这里有一个教程,但基本的设置是这样的:
HTML -这将有几个<a>
锚标记,每个锚标记包含各自的路由,如下所示:
<ul class="phones">
<li ng-repeat="phone in phones | filter:query | orderBy:orderProp" class="thumbnail">
<a href="#/phones/{{phone.id}}" class="thumb"><img ng-src="{{phone.imageUrl}}"></a>
<a href="#/phones/{{phone.id}}">{{phone.name}}</a>
<p>{{phone.snippet}}</p>
</li>
</ul>
然后你需要确保你设置你的应用程序使用ngRoute
:
var phonecatApp = angular.module('phonecatApp', [
'ngRoute',
'phonecatControllers'
]);
然后在配置中设置routeProvider
:
phonecatApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/phones', {
templateUrl: 'partials/phone-list.html',
controller: 'PhoneListCtrl'
}).
when('/phones/:phoneId', {
templateUrl: 'partials/phone-detail.html',
controller: 'PhoneDetailCtrl'
}).
otherwise({
redirectTo: '/phones'
});
}]);
指示ng-repeat
中的每个块使用templateUrl
中定义的部分。
当然,你还必须在你的控制器中定义行为,但这应该让你开始基本的路由。
相关文章:
- 使用JQuery在遗留html中加载动态AngularJS
- 错误:无法在“XMLHttpRequest”上执行“发送”:无法加载“文件”:AngularJS SPA
- 将图像数据加载到Angularjs中
- 在应用程序加载和 angularjs 中的每个状态更改时调用 jquery 插件
- 如何使用 RESTful 访问加载包含 AngularJS 的 HTML
- 如何将 json 文件加载到 Angularjs 中进行 ng-repeat
- 脚本不加载:将AngularJS与JSON(Firebase)一起使用
- 动态加载的AngularJS不工作
- 如何将模块正确加载到angularJS中
- 如何检查我所有的 html 内容是否加载在 angularjs 中
- 通过AJAX加载整个AngularJS页面
- 如何等待数据加载到AngularJS中
- 用NodeJS加载的AngularJS显示数据
- 将本地JSON加载到AngularJS中的Jasmine/Karma单元测试中
- 在使用ocLazyLoad时注入到惰性加载的AngularJS控制器中
- 无法将控制器加载到angularjs模块中
- 何时$on加载需要 AngularJS 应用程序
- 用于ftscroll的图像延迟加载器(AngularJS)
- 等待,直到所有数据都加载完成.AngularJS
- 等到图像加载到angularjs工厂中