我有一个页面会显示多个部分,具体取决于数据库值。目前我只是使用show / hide来显示div但是我想以适当的Angular方式做到这一点,但我一直遇到麻烦。
我的routes.js是
exports.index = function(req, res){
res.render('index');
};
exports.partials = function (req, res) {
var name = req.params.name;
res.render('partials/' + name);
};
我的控制器
function AppCtrl($scope, $http, $q, socket, $location) {
$scope.config = [[ return variables from HTTP call ]]
if($scope.config.name =='video') $scope.mainpVideo ==true;
else $scope.mainpVideo ==false;
if($scope.config.name =='audio') $scope.mainpAudio ==true;
else $scope.mainpAudio ==false;
if($scope.config.embed =='qa') $scope.qa ==true;
else $scope.qa ==false;
Index.jade
#box-1-content.auth-form-body(ng-show="mainpAudio" )
include partials/audio
ul.presenterList
li Presenters:
li(ng-repeat='presenter in presenters' ){{ presenter.name }}
br.clr
#box-1-content.auth-form-body(ng-show="mainpVideo" )
include partials/video
ul.presenterList
li Presenters:
li(ng-repeat='presenter in presenters' ){{ presenter.name }}
br.clr
#box-2-content.auth-form-body(ng-show="qa" )
include partials/qa
br.clr
.......
正如所说的单个页面,并且根据数据库中的配置存储将包含多个部分,如何做到这一点?
答案 0 :(得分:0)
我不认识Jade,但我猜是像
div(ng-include="'partials/' + config.name")
会做你想做的事。
答案 1 :(得分:0)
我通过使用ng-switch-when并在范围
中设置2个变量来解决它