Zur*_*iel 1 routes angularjs angular-routing
我已经设置了一个特殊的angular路径,这是许多静态页面的单一路径,(想想隐私策略,客户端html,我希望我的客户能够作为html页面放入一个文件夹,并动态加载它路由.
当您在地址栏中键入内容时,我告诉角色去查看目录并找到带有$ routeParams.name的.html文件并加载它.
这很好,但我将数据替换为空白页. blank.html
App.js
.config(function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider.when('/test', {
controller : 'AppRepeatCtrl',
templateUrl : './templates/test_tpl.html'
}).when('/:name', {
controller: 'DynamicRoutes',
templateUrl: 'partials/blank.html'
}).otherwise({
redirectTo: '/'
});
Run Code Online (Sandbox Code Playgroud)
})
Controllers.js
function DynamicRoutes ($scope, $http, $location, $route, $routeParams, $compile, appLoading) {
if ($routeParams.name == '' ) {
$route.current.templateUrl = 'partials/' + "home.html";
} else {
$route.current.templateUrl = 'partials/' + $routeParams.name + ".html";
}
$http.get($route.current.templateUrl).then(function (msg) {
if (msg.data.contains('html')) {
$http.get('partials/error.html').then(function (msg) {
$('#ng-view').html($compile(msg.data)($scope));
});
} else {
appLoading.ready();
$('#ng-view').html($compile(msg.data)($scope));
}
});
};
Run Code Online (Sandbox Code Playgroud)
我的问题是,有没有办法从部分加载页面,而不必加载空白模板,然后用静态页面替换html.因为我正在做动画,动画因为替换而变得僵硬.我真的需要在页面中加载而不必替换blank.html模板页面,或者在视图开始动画之前替换blank.html
$( '#NG-视图')的HTML($编译(msg.data)($范围)); 我认为是在没有ng-animate输入视图完成的情况下导致页面替换html的原因.
因为如果你把它改成$('#ng-view').append($ compile(msg.data)($ scope));
你可以看到2 x和1有动画但是一旦附加发生动画停止.
首先,不要在控制器中加载模板,这不是角度方式.
您不需要加载blank.html只是因为您必须提供模板,templateUrl可以是一个函数,您可以在其中确定要加载的模板.
$routeProvider.when('/:name', {
controller : 'DynamicRoutes',
templateUrl : function (params) {
console.log(params); // check the console to see what are passed in here
//return a valid Url to the template, and angular will load it for you
}
});
Run Code Online (Sandbox Code Playgroud)