Layout 如何使用角度材质实现动态弯曲值
我正在尝试构建一个子div数量不确定的div,我希望子div只有一个时具有Layout 如何使用角度材质实现动态弯曲值,layout,angular-material,Layout,Angular Material,我正在尝试构建一个子div数量不确定的div,我希望子div只有一个时具有flex=“100”,这将占用整行。如果有多个子div(即使有三个或四个子元素),它们都应该正好有flex=“50”,这将占据行的一半 知道我怎么做吗? 提前感谢。在元素中定义“flex”总是试图占用父元素允许的最大空间,而不向flex提供任何参数。这需要与layout=“row/column”一起使用,因此flex的扩展方向正确 这就是你要找的吗? 请注意,最终,项目将开始超出父级大小。你可以用几种方法解决这个问题,但
flex=“100”
,这将占用整行。如果有多个子div(即使有三个或四个子元素),它们都应该正好有flex=“50”
,这将占据行的一半
知道我怎么做吗?
提前感谢。在元素中定义“flex”总是试图占用父元素允许的最大空间,而不向flex提供任何参数。这需要与layout=“row/column”一起使用,因此flex的扩展方向正确
这就是你要找的吗?
请注意,最终,项目将开始超出父级大小。你可以用几种方法解决这个问题,但我相信这超出了问题的范围
HTML
<div ng-app="MyApp" ng-controller="AppCtrl as ctrl">
<h2>Static height list with Flex</h2>
<md-button class="thebutton" ng-click="addItem()">Add Item</md-button>
<div class="page" layout="row">
<md-list layout-fill layout="column">
<md-list-item flex layout="column" class="listitem" ng-repeat="item in items" ng-click="logme('Unrelated action')">
<md-item-content layout="column" md-ink-ripple flex>
<div class="inset">
{{item.title}}
</div>
</md-item-content>
</md-list-item>
</md-list>
</div>
</div>
JS
.page {
height: 300px; /* Or whatever */
}
.thebutton {
background-color: gray;
}
.listitem {
/*height: 100px;*/
flex;
background-color: pink;
}
angular.module('MyApp', ['ngMaterial'])
.controller('AppCtrl', function($scope) {
$scope.items = [{
title: 'Item One',
active: true
} ];
$scope.addItem = function() {
newitem = {
title: 'Another item',
active: false
};
$scope.items.push(newitem);
}
$scope.toggle = function(item) {
item.active = !item.active;
console.log("bool toggled");
}
$scope.logme = function(text) {
alert(text);
console.log(text);
}
});
在元素中定义“flex”总是试图占用父元素允许的最大空间,而不向flex提供任何参数。这需要与layout=“row/column”一起使用,因此flex的扩展方向正确
这就是你要找的吗?
请注意,最终,项目将开始超出父级大小。你可以用几种方法解决这个问题,但我相信这超出了问题的范围
HTML
<div ng-app="MyApp" ng-controller="AppCtrl as ctrl">
<h2>Static height list with Flex</h2>
<md-button class="thebutton" ng-click="addItem()">Add Item</md-button>
<div class="page" layout="row">
<md-list layout-fill layout="column">
<md-list-item flex layout="column" class="listitem" ng-repeat="item in items" ng-click="logme('Unrelated action')">
<md-item-content layout="column" md-ink-ripple flex>
<div class="inset">
{{item.title}}
</div>
</md-item-content>
</md-list-item>
</md-list>
</div>
</div>
JS
.page {
height: 300px; /* Or whatever */
}
.thebutton {
background-color: gray;
}
.listitem {
/*height: 100px;*/
flex;
background-color: pink;
}
angular.module('MyApp', ['ngMaterial'])
.controller('AppCtrl', function($scope) {
$scope.items = [{
title: 'Item One',
active: true
} ];
$scope.addItem = function() {
newitem = {
title: 'Another item',
active: false
};
$scope.items.push(newitem);
}
$scope.toggle = function(item) {
item.active = !item.active;
console.log("bool toggled");
}
$scope.logme = function(text) {
alert(text);
console.log(text);
}
});
在元素中定义“flex”总是试图占用父元素允许的最大空间,而不向flex提供任何参数。这需要与layout=“row/column”一起使用,因此flex的扩展方向正确
这就是你要找的吗?
请注意,最终,项目将开始超出父级大小。你可以用几种方法解决这个问题,但我相信这超出了问题的范围
HTML
<div ng-app="MyApp" ng-controller="AppCtrl as ctrl">
<h2>Static height list with Flex</h2>
<md-button class="thebutton" ng-click="addItem()">Add Item</md-button>
<div class="page" layout="row">
<md-list layout-fill layout="column">
<md-list-item flex layout="column" class="listitem" ng-repeat="item in items" ng-click="logme('Unrelated action')">
<md-item-content layout="column" md-ink-ripple flex>
<div class="inset">
{{item.title}}
</div>
</md-item-content>
</md-list-item>
</md-list>
</div>
</div>
JS
.page {
height: 300px; /* Or whatever */
}
.thebutton {
background-color: gray;
}
.listitem {
/*height: 100px;*/
flex;
background-color: pink;
}
angular.module('MyApp', ['ngMaterial'])
.controller('AppCtrl', function($scope) {
$scope.items = [{
title: 'Item One',
active: true
} ];
$scope.addItem = function() {
newitem = {
title: 'Another item',
active: false
};
$scope.items.push(newitem);
}
$scope.toggle = function(item) {
item.active = !item.active;
console.log("bool toggled");
}
$scope.logme = function(text) {
alert(text);
console.log(text);
}
});
在元素中定义“flex”总是试图占用父元素允许的最大空间,而不向flex提供任何参数。这需要与layout=“row/column”一起使用,因此flex的扩展方向正确
这就是你要找的吗?
请注意,最终,项目将开始超出父级大小。你可以用几种方法解决这个问题,但我相信这超出了问题的范围
HTML
<div ng-app="MyApp" ng-controller="AppCtrl as ctrl">
<h2>Static height list with Flex</h2>
<md-button class="thebutton" ng-click="addItem()">Add Item</md-button>
<div class="page" layout="row">
<md-list layout-fill layout="column">
<md-list-item flex layout="column" class="listitem" ng-repeat="item in items" ng-click="logme('Unrelated action')">
<md-item-content layout="column" md-ink-ripple flex>
<div class="inset">
{{item.title}}
</div>
</md-item-content>
</md-list-item>
</md-list>
</div>
</div>
JS
.page {
height: 300px; /* Or whatever */
}
.thebutton {
background-color: gray;
}
.listitem {
/*height: 100px;*/
flex;
background-color: pink;
}
angular.module('MyApp', ['ngMaterial'])
.controller('AppCtrl', function($scope) {
$scope.items = [{
title: 'Item One',
active: true
} ];
$scope.addItem = function() {
newitem = {
title: 'Another item',
active: false
};
$scope.items.push(newitem);
}
$scope.toggle = function(item) {
item.active = !item.active;
console.log("bool toggled");
}
$scope.logme = function(text) {
alert(text);
console.log(text);
}
});
感谢@William S的帮助,我不应该使用flex box进行静态大小的布局 所以我和ng班一起解决我的问题 HTML:
$scope.test
的初始值是'test1'
,通过将值从'test1'
更改为'test2'
,子div的宽度将设置为50%。感谢@William S的帮助,我不应该使用flex box进行静态大小布局
所以我和ng班一起解决我的问题
HTML:
$scope.test
的初始值是'test1'
,通过将值从'test1'
更改为'test2'
,子div的宽度将设置为50%。感谢@William S的帮助,我不应该使用flex box进行静态大小布局
所以我和ng班一起解决我的问题
HTML:
$scope.test
的初始值是'test1'
,通过将值从'test1'
更改为'test2'
,子div的宽度将设置为50%。感谢@William S的帮助,我不应该使用flex box进行静态大小布局
所以我和ng班一起解决我的问题
HTML:
$scope.test
的初始值是'test1'
,通过将值从'test1'
更改为'test2'
,子div的宽度将设置为50%。另一种方法是
和在控制器中定义和修改flexSize
,例如$scope.flexSize=50
另一种方法是
并在控制器中定义和修改flexSize
,例如$scope.flexSize=50
另一种方法是
并在控制器中定义和修改flexSize
,例如$scope.flexSize=50
另一种方法是
并在控制器中定义和修改flexSize
,例如$scope.flexSize=50代码>使用以下代码:
scope.flexSize = countryService.market === 'FR'? 40: 50;
使用以下内容:
scope.flexSize = countryService.market === 'FR'? 40: 50;
使用以下内容:
scope.flexSize = countryService.market === 'FR'? 40: 50;
使用以下内容:
scope.flexSize = countryService.market === 'FR'? 40: 50;
谢谢威廉,但这不是我想要的。当有多个子元素(即:2、3、4、5……)时,我需要子元素正好具有flex=“50”
。当有三个孩子时,您的代码将为每个孩子生成flex=“33”
flex=“25”
对于每个子元素,当它们有四个时,等等。很抱歉,我已经更新了我的问题。@在这种情况下,我建议您使用position:absolute,或者在position:relative时为您的项目元素定义px大小。flexbox的真正目的是根据其父项进行自我调整,而不是强制使用静态大小并溢出剩余的内容。谢谢您的帮助,@William S。谢谢William,但这不是我要找的。当有多个子元素(即:2、3、4、5……)时,我需要子元素正好具有flex=“50”
。当有三个孩子时,您的代码将为每个孩子生成flex=“33”
flex=“25”
对于每个子元素,当它们有四个时,等等。很抱歉,我已经更新了我的问题。@在这种情况下,我建议您使用position:absolute,或者在position:relative时为您的项目元素定义px大小。flexbox的目的就是调整