0

当我在 body 标签上使用ng-app='myApp'指令时,它会抛出' element[0].setTabbarVisibility is not a function ' 错误。

如果我不包括 ng-app,它工作正常。

为什么会这样?

var module=ons.bootstrap('myApp',['onsen']);
module.controller('MainController',function($scope){
console.log("Main controller");
});


<body  ng-app="FirstProject" ng-controller="MainController">
<ons-tabbar>
  <ons-tab label="tab1" page="tab1.html" active>
  </ons-tab>
  <ons-tab label="tab2" page="tab2.html">
  </ons-tab>
</ons-tabbar>

<ons-template id="tab1.html">
  <ons-page>
    <p style="text-align: center;">
      This is the first page.
    </p>
  </ons-page>
</ons-template>


<ons-template id="tab2.html">
  <ons-page>
    <p style="text-align: center;">
      This is the second page.
    </p>
  </ons-page>
</ons-template>


</body>
4

1 回答 1

0

尝试在body标签之后编写javascript代码,它对我有用

<body  ng-app="FirstProject" ng-controller="MainController">
<ons-tabbar>
<ons-tab label="tab1" page="tab1.html" active>
</ons-tab>
<ons-tab label="tab2" page="tab2.html">
</ons-tab>
</ons-tabbar>

<ons-template id="tab1.html">
 <ons-page>
  <p style="text-align: center;">
  This is the first page.
  </p>
 </ons-page>
</ons-template>


<ons-template id="tab2.html">
 <ons-page>
  <p style="text-align: center;">
  This is the second page.
  </p>
 </ons-page>
 </ons-template>
 </body>
 <script>
  var module=ons.bootstrap('myApp',['onsen']);
  module.controller('MainController',function($scope){
  console.log("Main controller");
  });
 </script>
于 2017-08-22T09:37:50.820 回答