ルーティング情報を使用して、ルート変更時にナビゲーションバーの HTML を変更したいと考えています。以下のコードでほぼ動作するようになりますが、データが DOM に到着したときに HTML として解析されません。このサービスを使ってみまし$sce
たが、実際にはどこにも行きませんでした。
ルート変更時に HTML を編集する他の (より良い) 方法がある場合は、お知らせください。
HTML :
<nav>
<div ng-controller="BrandCtrl">
<div class="nav-brand">
{{brand}}
</div>
</div>
</nav>
<div ng-view></div>
JS :
var app = angular.module("app", ['ngRoute']);
app.controller("BrandCtrl", function($scope, $route) {
$scope.$on('$routeChangeSuccess', function() {
var html = $route.current.html;
$scope.brand = html;
});
});
app.config(function ($routeProvider) {
$routeProvider
.when('/next-page', {
templateUrl: 'partials/next-page.html',
controller: 'BrandCtrl',
html: '<h3>New brand</h3>'
});