【问题标题】:Angularjs ng-hide not working with ng-include templateAngularjs ng-hide 不适用于 ng-include 模板
【发布时间】:2016-12-24 18:25:12
【问题描述】:

谁能帮帮我。 在 index.html 中,我运行 ng-view,代码对应 Routing.js 文件。该菜单调用两个页面 main.html 和 product.htm。 main.htm 包含另一个页面,称为 filterApp.html。 我需要隐藏一个嵌入 main.html 和 filterApp.html 的页面元素。我没有成功。 如果我采用包含并将代码直接放入 main.html 作品中。我读到了 ng-ng-hide 并包括无法正常工作。有什么我可以做的。我需要将它放在单独的文件中。 这是页面的代码。 非常感谢

索引.html

<html ng-app="appDataBoard">
<body ng-controller="mainController" >
 <ul >
          <li class="nav-item start open">
              <a href="#/main" class="nav-link nav-toggle"></a>
             </li>
               <li class="nav-item  ">
                            <a href="#/product" class="nav-link nav-toggle"> </a>
                 </li>
        </ul>

<div class="col-md-12 column sortable">
                           <div ng-view></div>
                </div>
</body>
</html>

Main.html

<div class="jumbotron text-center">
    <h1>main  Page</h1>

    <p>{{ message }}</p>
</div>

<!-- INCLUDE FILTER APPS-->
        <div ng-include="'./template/filterApp.html'" ></div>

产品.html

<div class="jumbotron text-center">
    <h1>Product Page</h1>

    <p>{{ message }}</p>
p ng-hide="hide1">este parrafo se debe borrar</p>
</div>

filterApp.html

<div ng-hide="hselect1"  >
            <select id="select-1" multiple="multiple" onchange="RecargaSelectBU()" >
            </select>
        </div>

路由.js

// create the module and name it dbApp
    var dbApp = angular.module('appDataBoard', ['ngRoute']);

    // configure our routes
    dbApp.config(function($routeProvider) {
        $routeProvider

            // route for the home page
            .when('/main', {
                templateUrl : 'template/main.html',
                controller  : 'mainController'
            })

            // route for the about page
            .when('/product', {
                templateUrl : 'template/product.html',
                controller  : 'productController'
            })

    });

    // create the controller and inject Angular's $scope
    dbApp.controller('mainController', function($scope) {
        // create a message to display in our view
        $scope.message = 'Pagina principal';
        $scope.hselect1 = true;
    });

    dbApp.controller('productController', function($scope) {
        $scope.message = 'Pagina de producto.';
        $scope.hide1 = true;

    });

【问题讨论】:

  • 您要么需要为此提供服务,要么允许它们共享同一个控制器。你能把你的代码放在 plunkr 上吗?

标签: angularjs templates ng-hide angularjs-ng-include


【解决方案1】:

检查这个 plunker 链接。它对我来说工作正常。 https://embed.plnkr.co/RZDGdnFEq1SmT7F3ncZa/

【讨论】:

  • 艾哈迈德工作正常。这是我的经验不足。非常感谢你的帮助 。问候
  • @CesarBugari 欢迎我的荣幸
猜你喜欢
  • 2014-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-08
  • 2014-03-27
  • 2016-11-13
  • 2015-06-29
  • 2018-06-18
相关资源
最近更新 更多