您好我想使用类似的功能: Using Inline Templates in Angular
但在我的情况下,网址将是动态的。例如,在下面的代码中,url将具有/ first或/ second,但在我的情况下,它将具有类别id。可以有100个类别,所以我无法写出100个条件
learningApp.config(function ($routeProvider) {$routeProvider.
when("/cat1",{ controller: "SimpleController", templateUrl: "temp1.html"}).
when("/cat2", {controller: "SimpleController", templateUrl: "temp2.html"}).
otherwise({redirectTo : "/first"});
});
<script type="text/ng-template" id="cat1.html">
<div class="view">
<h2>First View</h2>
<p>
Search:<input type="text" ng-model="filterText" />
</p>
<ul class="nav nav-pills">
<li ng-repeat="cust in customers | orderBy:'name' | filter: filterText "><a href="#">{{cust.name}} - {{cust.school}}</a></li>
</ul>
</div>
</script>
<script type="text/ng-template" id="cat2.html">
<div class="view">
<h2>Second View</h2>
<p>
Search:<input type="text" ng-model="filterText" />
</p>
<ul class="nav nav-pills">
<li ng-repeat="cust in customers | orderBy:'name' | filter: filterText "><a href= "#">{{cust.name}} - {{cust.school}}</a></li>
</ul>
</div>
并且我肯定会有一个id为类别ID的部分,对应于每个类别。
答案 0 :(得分:0)
您可以像这样指定您的网址:
cfg['dbconfig']
在你的控制器内:
.when("/category/:catId") {
controller: "ControllerName",
templateUrl: "templateURL",
}
E.g。 - 导航到“/ category / 1”将导致.controller('ControllerName', ['$scope', '$routeParams', function($scope, $routeParams) {
var $scope.categoryFromRoute = $routeParams.catId;
}]);
在控制器内具有等于1的值。