我有以下javascript对象,我正在构建我的导航栏:
$scope.slo = [ { main: "IJS", url: "https://www.ijs.si/ijsw" }, { main: "ZIC", icon: "glyphicon glyphicon-triangle-bottom", submenu: [{ one: "predstavitev", two: "osebje" }] }, { main: "knjižnica", icon: "glyphicon glyphicon-triangle-bottom", submenu: [{ one: "tiskane revije", two: "elektronske revije", three: "baze podatkov", four: "katalog(COBISS)" }] }, { main: "storitve", icon: "glyphicon glyphicon-triangle-bottom", submenu: [{ one: "bibliografije", two: "medknjižni?na izposoja", three: "fotokopirnica" }] } ]; $scope.eng = [{ main: "IJS" }, { main: "ZIC", icon: "glyphicon glyphicon-triangle-bottom", submenu: [{ one: "introduction", two: "staff" }] }, { main: "library", icon: "glyphicon glyphicon-triangle-bottom", submenu: [{ one: "printed journals", two: "electronic journals", three: "databases", four: "catalogue(COBISS)" }] }, { main: "services", icon: "glyphicon glyphicon-triangle-bottom", submenu: [{ one: "bibliographies", two: "interlibrary loan", three: "copy room" }] }];
现在我想在ng-href
我的html中添加一个标记,但前提是该url
属性存在.因此,例如第一个栏会指向一个网址,但其余的则不会因为它们是下拉.
这是我的html标记:
{{ menu.main }}
我的问题是,我可以提出一个条件ng-href
来评估url
属性是否存在,然后绑定urls属性值?如果可以的话,我该怎么做?
使用我目前的标记,我只得到:
IJS ZIC
Arkantos.. 5
您应该使用ng-attr-*
有条件地向标记添加属性
{{ menu.main }}
href
只有当有效值时,才会为锚标记添加属性menu.url
.如果{{menu.url}}
解析为undefined
then ,则不href
会将属性添加到元素中.
您应该使用ng-attr-*
有条件地向标记添加属性
{{ menu.main }}
href
只有当有效值时,才会为锚标记添加属性menu.url
.如果{{menu.url}}
解析为undefined
then ,则不href
会将属性添加到元素中.