【问题标题】:Questions about typescipt rules in angular application关于angular应用中typescript规则的问题
【发布时间】:2022-11-15 17:14:13
【问题描述】:

我对角度的打字稿代码规则有一些疑问。

1:初始化变量 有几种定义变量的可能性,但是用角度初始化变量不是必需的吗?因为我可以使用?没有初始化。

public variable?;
public variable = "string";

我只想知道,哪个更好?

2:在html中使用方法调用的好方法吗 如

<componentName [clu] = getClu()>

<componentName>

或者 我在ts文件中定义了一个变量

public cluValues 

private getClu(){

this.cluValues = ...

}
<componentName [clu] = cluValues>

<componentName>

哪一个更好?

谢谢你的回答

【问题讨论】:

    标签: angular typescript


    【解决方案1】:
    Click popup open but data not showing Please solve the problem in app script please help me
    
    
    Index:
    
    
    <!DOCTYPE html>
    <html>
      <head>
        <base target="_top">
        <?!=include ('CSS');?>
       
      </head>
      <body>
        <div class="container">
          <div class="row">
    
    
            <? data.forEach(row=>{?>
    
                  <div class="card m-3" style="width: 18rem;">
                    <img src="https://drive.google.com/uc?export=download&id=<?!= row[10]  ?>" class="card-img-top" alt="...">
                    <div class="card-body">
                      <h5 class="card-title"><?!=row[1] + '  '  + row[2]  ?></h5>
                      <p class="card-text"><?!=row[3] + ' |# '+ row[4] + ' |# '+ row[5] ?> </p>
                      <buttom type="buttom" class="btn btn-primary"data-bs-toggle="modal" data-bs-target="#exampleModal"data-bs-player="<?!= row ?>"> Go somewhere</a>
                    </div>
                  </div>
            
            <? }); ?>
    
    
    
    <!-- Modal -->
    
          <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog">
              <div class="modal-content">
                <div class="modal-header bg">
                  
                  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                
                  <div class="modal-body bg">
                   <div class="row d-flex align-items-center">
                    <div class="col-md-6">
                      <img src=" " class="modal-img" alt="playerImage">
                    </div>
                      <div class="col-md-6 align-middle playerInfo">
                        <h2 class="modal-body-lastName"></h2>
                        <h2 class="modal-body-Name"></h2>
                        <h6 class="modal-body-basic-info"></h6>
                    </div>
                  </div>
                 </div>
                  <div class="modal-footer">
                  <div class="container">
    
                    <div class="row">
                      <div class="col text-center">
                        <h4> PPP </h4> </br>
                        <h4 class="modal-footer-ppp"></h4>
                      </div>
                    <div class="col text-center">
                      <h4> RPP </h4> </br>
                      <h4 class="modal-footer-rpp"></h4>
                    </div>
                    <div class="col text-center">
                      <h4> APP </h4> </br>
                      <h4 class="modal-footer-app"></h4>
                      
                     </div>
                      </div>
                     </div>
                </div>
               </div>
                </div>
                </div>
              </div>
            </diV>  
         </diV>
              <?!=include ( 'JS');?>
    
    
    
    
       
      </body>
    </html>
    
    
    
    
    CSS:
    
    <!-- CSS only -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
    
    <style>
    
    body{
      padding:20px;
    }
    .bg{
      background-color: #1D76BC;
    }
    .playerInfo{
      vertical-align:middle;
      color:white;
    }
    </style>
    
    
    Js:
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
    
    <script>
      var exampleModal = document.getElementById('exampleModal')
      exampleModal.addEventListener('show.bs.modal', function (event) {
        // Button that triggered the modal
        var button = event.relatedTarget
        // Extract info from data-bs-* attributes
        var recipient = button.getAttribute('data-bs-player')
        // If necessary, you could initiate an AJAX request here
        // and then do the updating in a callback.
    
        
          var playerInfo=recipient.split(".");
          console.log( playerInfo );
    
         // get the attribute value into variables
          var modalLastName = exampleModal.querySelector('.modal-LastName')
          var modalImag = exampleModal.querySelector('.modal-img')
          var modalName = exampleModal.querySelector('.modal-name')
          var modalBasicInfo = exampleModal.querySelector('.modal-basic-info')
    
           var modalPPP = exampleModal.querySelector('.modal-footer-ppp')
           var modalRPP = exampleModal.querySelector('.modal-footer-rpp')
           var modalAPP = exampleModal.querySelector('.modal-footer-app')
    
        // Update the modal's content.
        modalLastName.textContent = player[1];
        modalName.textContent = player[2];
        modalImag.src"https://drive.google.com/uc?export=view&id= "  + player[10];
        modalBasicInfo.textContent = player[3] +'|'+player[4] +'|'+player[5];
    
         modalPPP.textContent = player[6];
         modalRPP.textContent = player[7];
         modalAPP.textContent = player[8];
      
      })
    </script>
    

    【讨论】:

      猜你喜欢
      • 2019-09-21
      • 2021-06-18
      • 2017-02-25
      • 2021-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-29
      • 1970-01-01
      相关资源
      最近更新 更多