最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do you add a search bar to angular material? - Stack Overflow

programmeradmin3浏览0评论

I am trying to add a search input to an <md-toolbar> but there doesn't seem to be any styling for this. It seems adding a search bar would be a mon header element so perhaps I am missing something.

<md-toolbar md-theme="input">
    <md-input-container flex>
    <md-icon class="material-icons">&#xE8B6;</md-icon>
    <input ng-model="search.notes" placeholder="Search here">
    </md-input-container>
</md-toolbar>

Then in the JS:

app.config(['$mdThemingProvider', function($mdThemingProvider) {
    $mdThemingProvider.theme('input')
        .primaryPalette('blue')
        .accentPalette('pink')
        .warnPalette('red')
        .backgroundPalette('grey');
}]);

However, while the element does show up - it's clear this is not the intended way it should be used since neither the spacing, font-color, or alignment match up.

I am trying to add a search input to an <md-toolbar> but there doesn't seem to be any styling for this. It seems adding a search bar would be a mon header element so perhaps I am missing something.

<md-toolbar md-theme="input">
    <md-input-container flex>
    <md-icon class="material-icons">&#xE8B6;</md-icon>
    <input ng-model="search.notes" placeholder="Search here">
    </md-input-container>
</md-toolbar>

Then in the JS:

app.config(['$mdThemingProvider', function($mdThemingProvider) {
    $mdThemingProvider.theme('input')
        .primaryPalette('blue')
        .accentPalette('pink')
        .warnPalette('red')
        .backgroundPalette('grey');
}]);

However, while the element does show up - it's clear this is not the intended way it should be used since neither the spacing, font-color, or alignment match up.

http://codepen.io/Xeoncross/pen/rLxEqv

Share Improve this question edited Jan 8, 2020 at 13:13 Miss Chanandler Bong 4,25811 gold badges29 silver badges39 bronze badges asked Jun 11, 2016 at 18:34 XeoncrossXeoncross 57.3k83 gold badges271 silver badges371 bronze badges 1
  • So what's missing? Expectations are not clear – charlietfl Commented Jun 11, 2016 at 18:43
Add a ment  | 

1 Answer 1

Reset to default 1

While this doesn't solve the problem of trying to use md-input inside a toolbar/header. You can make md-content look like a toolbar of sorts by making the content area dark so it stands out from regular md-content blocks. Kind of a work around the problem if you don't mind black.

<md-content md-theme="input" layout="column" layout-padding>
  <md-input-container style="padding-bottom: 0; margin-bottom: 0">
     <md-icon class="material-icons">&#xE8B6;</md-icon>
     <input ng-model="search.notes" placeholder="Search here">
  </md-input-container>
</md-content>

and the theme js:

app.config(['$mdThemingProvider', function($mdThemingProvider) {
    $mdThemingProvider.theme('input')
      .primaryPalette('blue')
      .dark();                 // <----- Note
  }
]);

Example here: http://codepen.io/Xeoncross/pen/jrWgqY

发布评论

评论列表(0)

  1. 暂无评论