One place for hosting & domains

      How to Fix the 500 Internal Server Error in WordPress (10 Tips)


      Seeing a 500 internal server error where your website should be is enough to throw anyone into a panic. When your website goes down, you lose out on potential traffic and sales. If it’s offline for a while, it can also negatively impact your Search Engine Optimization (SEO) efforts.

      Fortunately, there are plenty of ways to go about fixing this error. Many of these solutions are fairly straightforward, and you don’t need a lot of technical know-how to start troubleshooting.

      In this guide, we’ll cover what the 500 internal server error in WordPress is and discuss some potential causes. Then we’ll give you 10 tips to help you get your website back in working order.

      1. Back up your website.
      2. Try reloading the page.
      3. Clear your browser cache.
      4. Access your error logs.
      5. Check for the “Error Establishing a Database Connection.”
      6. Look for permission errors.
      7. Increase your PHP memory limit.
      8. Check for problems with your .htaccess file.
      9. Look for coding or syntax errors in your CGI/Perl script.
      10. Ask your web host about potential server issues.

      Let’s get started!

      Dealing with the WordPress Internal Server Error?

      Avoid troubleshooting when you sign up for DreamPress. Our friendly WordPress experts are available 24/7 to help solve website problems — big or small.

      What Is the 500 Internal Server Error?

      The 500 internal server error is frustratingly nonspecific. When the error occurs, you usually don’t get many details about it. In fact, you might not receive any information at all.

      An example of a 500 internal server error screen.

      The 500 error is a generic issue that isn’t specific to WordPress. Chances are you’ve seen it before during your internet explorations. Despite the name, it doesn’t necessarily mean that something is wrong with your server. It could be an issue with your website or browser.

      If you do see this error on your site, you’ll want to get it fixed as quickly as possible. A 500 error can impact your SEO if allowed to linger. If your site is crawled while it’s offline, there’s a chance that Google may interpret the error as an issue with your website.

      This error can also hurt your User Experience (UX) and give visitors the impression that you’re unprofessional. Not only can a poor UX affect the way Google ranks your site, but it can cause you to lose customers as well. After all, you can’t do business if your site isn’t accessible.

      A wide variety of situations can result in the 500 error, making it a bit of a chore to sort out. Potential causes of the 500 internal server error in WordPress include:

      • Plugin compatibility issues
      • Exhausted PHP memory limit
      • Corrupted files
      • Coding or syntax errors

      The fact that the error message itself tends to be vague doesn’t help. Fortunately, you can solve many of these issues on your own with a bit of know-how.

      Variations on the 500 Internal Server Error

      Depending on your operating system, browser, and the cause of the error, there are variations in how it will appear. For example, if a database connection can’t be established, you might see something like this:

      An error establishing a database connection message.

      A plain white screen, sometimes referred to as the White Screen of Death (WSoD), can indicate a 500 internal server error.

      A blank browser window due to a 500 error.

      Also, many site owners have the option to customize their 500 error messages. So you might see this error in many different forms.

      How to Fix the 500 Internal Server Error in WordPress (10 Tips)

      Now that you’ve had an introduction to the 500 internal server error, it’s time to discuss how to resolve it. Let’s take a look at ten tips you can use to fix this issue in WordPress.

      1. Back up your website.

      Before tinkering under the hood, it’s always smart to make a backup of your website. If DreamHost hosts your site, you can take advantage of our one-click backup feature. You can also create a manual backup if you prefer.

      To make a complete backup, you’ll need to save copies of your WordPress files as well as your databases. You can back up your site’s files using a Secure File Transfer Protocol (SFTP) client such as FileZilla.

      Once you’re connected to your server, navigate to the WordPress files you want to save. These files include the WordPress core installation, plugins, themes, images, and more. To save the files, simply right-click on them and select Download.

      How to download WordPress files via SFTP.

      Now you’ll need to back up your database, which you can do by logging into phpMyAdmin. Select the database you want to download from the left-hand panel, and then click on the Export tab.

      You’ll then need to choose between a “Quick” or a “Custom” export. The Quick export will likely work just fine unless you need to manage more advanced options.

      Options for downloading a WordPress database using phpMyAdmin.

      Click on the Go button, and your download should start. Once your website is safely backed up, you can get to work on fixing that 500 error.

      2. Try reloading the page.

      Let’s start with the best-case scenario. Some situations that cause a 500 internal error clear up on their own within a few minutes. For example, if you’ve just made changes to a plugin or theme, or if your host is experiencing unusually heavy traffic, you may see a server error. If this is true in your case, you’re in luck, as a simple page reload should get things back to normal.

      Therefore, the first thing to try is simply waiting a minute or two, during which the error will hopefully resolve itself. Then you can try reloading the page by pressing F5 or (command + R if you’re using a Mac).

      3. Clear your browser cache.

      Another potential server error fix that’s quick and easy is clearing your browser cache. It’s possible the cache became corrupted, which would cause problems when attempting to access websites.

      First, you might check Down For Everyone Or Just Me. This will determine whether there’s a widespread problem or you’re the only one experiencing difficulties.

      Amazon.com’s status on Down for Everyone or Just Me.

      If you’re alone in your 500 error frustration, the problem may be your browser. Try accessing your site from a different browser. If an alternative works, it’s a sign that the issue is with your cache.

      In Google Chrome, you can clear your cache by pressing Ctrl + Shift + Delete. Alternatively, you can click on the three vertical dots in the top-right corner, followed by More tools > Clear browsing data.

      Options for clearing the browser cache in Chrome.

      Be sure to check the Cached images and files box. Then click on the Clear data button.

      In Firefox, you can clear the cache using the Ctrl + Shift + Delete keyboard shortcut. This will open the Clear Recent History window. In the Time range to clear drop-down menu, select Everything. Check the Cache box, and then click on OK.

      Options for clearing browser data in Firefox.

      In Safari, you can navigate to the History menu item and choose Clear History. Keep in mind that this will delete everything, including cookies and visited pages.

      How to clear the browser cache in Safari.

      Once you’ve cleared your browser cache, you can attempt to access your website again. If you’re still seeing the 500 internal server error, it’s time to move on to more involved fixes.

      4. Access your error logs.

      Your site’s error logs may provide insight into what’s causing the 500 error. Depending on your host, these logs may be cycled quite often, so you’ll want to take a look as soon as possible.

      You can check your error logs by accessing your site’s files via SFTP and looking for the /logs directory. Next, select the site that’s experiencing the error. You may see several directories at this point. You’ll want to check the one with the most recent date.

      Error and access log files accessed via FileZilla.

      You can view the log by downloading it and opening it with your preferred text editor. Hopefully, your error logs will provide you with some additional context for the 500 error.

      Another option is to enable the WordPress debug log. You can do this by connecting to your site via SFTP and opening your wp-config.php file. Within it, look for the following line:

      define('WP_DEBUG', false);

      Once you find it, replace it with the following:

      define( 'WP_DEBUG', true );
      
      define( 'WP_DEBUG_DISPLAY', false );
      
      define( 'WP_DEBUG_LOG', true );

      This will create a debug.log file, which you can find under the /wp-content/ directory. Just be sure to change the WP_DEBUG value back to “false” when you’re done troubleshooting.

      5. Check for the ‘Error Establishing a Database Connection.’

      If there’s been a problem establishing a database connection, not only will your site be offline for visitors, but you won’t be able to access the WordPress admin dashboard either. There are a few possible causes of this:

      • Incorrect database login credentials
      • A corrupted WordPress database
      • A corrupted WordPress installation file

      Let’s start with incorrect login credentials, as this is a common cause of the database connection error. If you’re a DreamHost user, you can find your database credentials in your panel. However, if you use a different host, you’ll likely follow a similar procedure.

      Navigate to MySQL Databases and find the one that corresponds to your website under the Database(s) on this server section. Here, you’ll find your database name under the Database heading. The username is listed under the Users Access column.

      Alt-text: Where to find your MySQL username in DreamPanel.

      To find the password, click on the username. On the next screen, scroll down and click on the Show button next to the password field.

      How to find your database password in DreamPanel.

      Next, you’ll compare these credentials to those in your wp-config.php file. You can access this file in your site’s main directory via SFTP. Once you have the file downloaded, open it and verify that the information under MySQL Settings matches what you found in your panel.

      Checking MySQL settings in the wpconfig.php file.

      Next, if your database is corrupted, you can quickly repair it through phpMyAdmin. Log in and click on your database in the left panel. Select all of the tables in the database, and then choose the Repair table option from the drop-down menu.

      Repairing a database in phpMyAdmin.

      Finally, let’s look at how to handle a corrupted WordPress installation file. Start by downloading a new copy of WordPress and unzipping the file. You’ll need to delete the wp-content folder and the wp-config-sample.php file.

      Deleting files from a new WordPress installation.

      Upload the rest of the files to your site via SFTP, overwriting any existing ones. You now have a brand new, uncorrupted WordPress installation. You’ll also want to clear your browser cache before checking your website again.

      6. Look for permission errors.

      If any of your files have permissions set incorrectly, you may see the 500 internal server error as a result. Again, you can check and change these permissions using SFTP.

      Right-click on any file and select File permissions to open a new dialogue window. In this window, you can check and, if necessary, set new permissions for the file.

      Checking and updating file permissions using FileZilla.

      Typically, you’ll want to set files to “644” and directories and executables to “755”. However, you may want to check with your host if you’re unsure about the correct values.

      7. Increase your PHP memory limit.

      Another reason you might see the 500 internal server error is if you’ve exceeded your server’s PHP memory limit. There are several ways to increase your limit, and they all involve using SFTP.

      Before you try increasing your memory limit, you may want to start by seeing what it’s currently set to. You can do this through the WordPress admin dashboard. Keep in mind that, with some variations of the 500 error, you won’t be able to access the dashboard. If that’s the case, you may have to skip this step.

      From your WordPress dashboard, navigate to Tools > Site Health. Click on Info at the top of the screen, and scroll down to the Server section. You should see your PHP memory limit there.

      How to check your WordPress site’s PHP memory limit.

      To increase the PHP memory limit, there are a few files you can edit. One is your .htaccess file, typically located in your site’s root directory. Open the file and add the following code:

      php_value memory_limit xxxM

      You can replace the “xxx” with your desired amount of memory. Usually, 256M is plenty.

      You can also increase your memory limit by editing your php.ini file. You should be able to find this file in your root directory. If not, you can go ahead and create one. Add or update its code to the following:

      memory_limit = xxxM

      Another option is to add in the following code at the top of your wp-config.php file:

      define('WP_MEMORY_LIMIT', 'xxxM');

      If this resolves the 500 error, your next task will be to figure out what is causing the memory limit exhaustion. It could be a problematic plugin or theme. You might consider reaching out to your host for help on finding the exact server diagnostics.

      8. Check for problems with your .htaccess file.

      Your .htaccess file is one of the core WordPress files. It contains rules for your server, so it could contribute to a 500 internal server error.

      If your .htaccess file has become corrupted, you’ll want to go ahead and create a fresh one. Start by logging into your site via SFTP and finding your .htaccess file. Rename the file to .htaccess_old.

      Renaming a file in FileZilla.

      Now, create a new .htaccess file in your text editor and paste in the following:

      # BEGIN WordPress
      
      RewriteEngine On
      
      RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
      
      RewriteBase /
      
      RewriteRule ^index.php$ - [L]
      
      RewriteCond %{REQUEST_FILENAME} !-f
      
      RewriteCond %{REQUEST_FILENAME} !-d
      
      RewriteRule . /index.php [L]
      
      # END WordPress

      Go ahead and upload your newly created .htaccess file. Then refresh your site in your browser, and check to see whether the error message is showing.

      9. Look for coding or syntax errors in your CGI/Perl script.

      If you’re running Common Gateway Interface (CGI) scripts, any coding errors you’ve made could result in a 500 error. To unearth potential issues with your CGI scripts, log into your site using Secure Shell Access (SSH).

      Once you’ve logged in, you can troubleshoot your CGI with this command:

      [server]$ ./cgi_name.cgi

      The terminal should return a general error message and the line number the culprit is located on. From there, you can work your coding magic!

      When working with CGI, there are a few best practices to keep in mind to avoid problems. First, it’s wise to use a plain text editor to ensure that you maintain ASCII format. When you upload scripts, you should also be able to select ASCII mode in your FTP client.

      Changing the transfer type option in FileZilla.

      Finally, if necessary, upload to the cgi-bin directory on your server. Then you can double-check your files’ permissions once you have them uploaded.

      10. Ask your web host about potential server issues.

      If all else fails, there may be a server issue, which only your host can confirm. Unfortunately, if your host’s server is experiencing a problem, you may have to wait out some website downtime.

      If you’re a DreamHost client, you can check the DreamHost Status page. This resource provides you with information on all of our services.

      The DreamHost status page.

      If you run into any problems while trying to repair the 500 internal server error, you can always reach out to our tech support team. They’re ready and waiting to lend you a hand! If you’ve followed the tips in this guide, you’ll have plenty of valuable information for the technician.

      Ready to Dive into Your Error Log?

      Whether you need help with file permission, identifying a hidden file, or dealing with a faulty plugin, we can help! Subscribe to our monthly digest so you never miss an article.

      Let’s Get Your WordPress Website Back on Track

      While having to sort out a 500 internal server error isn’t exactly fun, it’s also not as painful as you might imagine. With a little patience and the tips we’ve provided, you should be able to make some progress on getting your website back online.

      You can start small by refreshing your page and clearing your browser cache. Then you might want to move onto more involved fixes, such as increasing your PHP memory limit. If you’re not able to resolve the error on your own, DreamHost’s award-winning tech support is just a click away.

      When you do run into errors, it’s easier to get back up and running when you have a reliable hosting provider. DreamPress is fast, secure WordPress hosting with powerful features to help make your site a success!



      Source link

      JavaScript の配列項目から反復するための .map() の使用方法


      はじめに

      古典的な forloop からforEach()メソッドまで、JavaScript のデータセットから反復するためにさまざまなテクニックとメソッドを使用します。最も一般的なメソッドの1つは、.map() メソッドです。.map() は、親配列内の各項目に特定の関数を呼び出すことから配列を作成します。配列の呼び出しだけを変化させる非変異メソッドに反するものとして、.map( ) は新しい配列を作成する非変異メソッドです。

      このメソッドには、配列で作業するときに多くの用途がある場合があります。このチュートリアルでは、JavaScript の .map() の 4 つの注目に値する使用を見てみましょう。配列要素の呼び出し、文字列を配列に変換、ライブラリのレンダリングリスト、配列オブジェクトの再フォーマットを行います。

      前提条件

      このチュートリアルではコーディングは必要ありませんが、例とともに次のものに興味がある場合、Node.js REPL またはブラウザ開発者ツールを使用することもできます。

      ステップ 1 — 配列内の各項目の関数を呼び出す

      .map() はコールバック関数を引数の 1 つとして受け入れ、その関数の重要なパラメータは関数によって処理される項目の現在の値です。これは必要なパラメータです。このパラメータにより、配列内の各項目を変更し、新しい関数を作成できます。

      次に例を示します。

      const sweetArray = [2, 3, 4, 5, 35]
      const sweeterArray = sweetArray.map(sweetItem => {
          return sweetItem * 2
      })
      
      console.log(sweeterArray)
      

      この出力はコンソールにログインします。

      Output

      [ 4, 6, 8, 10, 70 ]

      これにより、さらに簡素化できます。

      // create a function to use
      const makeSweeter = sweetItem => sweetItem * 2;
      
      // we have an array
      const sweetArray = [2, 3, 4, 5, 35];
      
      // call the function we made. more readable
      const sweeterArray = sweetArray.map(makeSweeter);
      
      console.log(sweeterArray);
      

      同様の出力はコンソールにログインします。

      Output

      [ 4, 6, 8, 10, 70 ]

      sweetArray.map(makeSweeter) のようなコードがあなたのコードを少し読みやすくします。

      ステップ 2 — 文字列を配列に変換

      .map() は配列プロトタイプに属することが知られています。このステップでは、文字列を使用して配列に変換します。ここでは文字列の機能のメソッドを開発しません。むしろ、特別な.call() メソッドを使用します。

      JavaScript のすべてはオブジェクトであり、メソッドはこうしたオブジェクトに付随する関数です。.call() により、別のオブジェクトのコンテキストを使用できます。したがって、配列の .map() のコンテキストを文字列にコピーします。

      .call() は、使用するコンテキストの引数と元の関数の引用のパラメータを渡すことができます。

      次に例を示します。

      const name = "Sammy"
      const map = Array.prototype.map
      
      const newName = map.call(name, eachLetter => {
          return `${eachLetter}a`
      })
      
      console.log(newName)
      

      この出力はコンソールにログインします。

      Output

      • [ "Sa", "aa", "ma", "ma", "ya" ]

      ここでは、文字列の .map() のコンテキストを使用して、.map() が予期する関数の引数を渡しています。

      この関数は、文字列の .split() メソッドのようなもので、配列に戻す前に各文字列の文字が変更できるだけです。

      ステップ 3 — JavaScript ライブラリのレンダリングリスト

      React のような JavaScript ライブラリは、リストの項目をレンダリングするために .map() を使用します。しかし、.map() メソッドは JSX 構文に含まれるため、これは JSX 構文を必要とします。

      React コンポーネントの例は次のとおりです。

      import React from "react";
      import ReactDOM from "react-dom";
      
      const names = ["whale", "squid", "turtle", "coral", "starfish"];
      
      const NamesList = () => (
        <div>
          <ul>{names.map(name => <li key={name}> {name} </li>)}</ul>
        </div>
      );
      
      const rootElement = document.getElementById("root");
      ReactDOM.render(<NamesList />, rootElement);
      

      これは、React のステートレスなコンポーネントであり、リストにより div をレンダリングします。各リスト項目は、最初に作成された名前の配列を繰り返すため、.map() を使用してレンダリングされます。このコンポーネントは、rootID を使用して DOM 要素の ReactDOM を使用します。

      ステップ 4 — 配列オブジェクトの再フォーマット

      .map() は、配列のオブジェクトを反復するために使用し、従来の配列に似た方法で、各オブジェクトの内容を変更し新しい配列を戻します。この変更は、コールバック関数で戻されるものに基づいて行われます。

      次に例を示します。

      const myUsers = [
          { name: 'shark', likes: 'ocean' },
          { name: 'turtle', likes: 'pond' },
          { name: 'otter', likes: 'fish biscuits' }
      ]
      
      const usersByLikes = myUsers.map(item => {
          const container = {};
      
          container[item.name] = item.likes;
          container.age = item.name.length * 10;
      
          return container;
      })
      
      console.log(usersByLikes);
      

      この出力はコンソールにログインします。

      Output

      [ {shark: "ocean", age: 50}, {turtle: "pond", age: 60}, {otter: "fish biscuits", age: 50} ]

      ここでは、ブラケットとドット表記を使用して、配列の各オブジェクトを修正します。このユースケースは、フロントエンドアプリケーションで保存または解析する前に、受信したデータを処理または縮約するために使用できます。

      まとめ

      このチュートリアルでは、JavaScript の .map() メソッドの 4 つの使用を見てきました。他のメソッドと組み合わせて、.map() の機能は拡張できます。詳しくは、JavaScript: 反復メソッドの記事にある配列メソッドの使用方法を参照してください。



      Source link

      AngularでViewChildを使用して、子コンポーネント、ディレクティブ、DOM 要素にアクセスする方法


      はじめに

      この記事では、AngularのViewChildデコレーターを紹介します。

      親コンポーネントクラスからディレクティブ、子コンポーネント、またはDOM要素にアクセスする場合があります。ViewChildデコレーターは、指定されたディレクティブ、コンポーネント、テンプレート参照セレクタに一致する最初の要素を返します。

      ディレクティブに対してViewChildを使用する

      ViewChildを使用すると、ディレクティブにアクセスすることができます。

      SharkDirectiveがあるとします。

      理想的には、@angular/cliを使用してディレクティブを生成します。

      • ng generate directive shark

      それ以外の場合は、app.module.tsに手動で追加する必要があります。

      app.module.ts

      import { SharkDirective } from './shark.directive';
      ...
      @NgModule({
        declarations: [
          AppComponent,
          SharkDirective
        ],
        ...
      })
      

      このディレクティブは、属性appSharkを持つ要素を検索し、要素内のテキストの先頭にSharkという単語を追加します。

      shark.directive.ts

      import {
        Directive,
        ElementRef,
        Renderer2
      } from '@angular/core';
      
      @Directive(
        { selector: '[appShark]' }
      )
      export class SharkDirective {
        creature="Dolphin";
      
        constructor(elem: ElementRef, renderer: Renderer2) {
          let shark = renderer.createText('Shark ');
          renderer.appendChild(elem.nativeElement, shark);
        }
      }
      

      次に、それを使用してコンポーネントテンプレートでFinSharkを追加します。

      app.component.html

      <span appShark>Fin!</span>
      

      ブラウザでアプリケーションを表示すると、次のように表示されます。

      Output

      Shark Fin!

      これで、SharkDirectivecreatureインスタンス変数にアクセスして、extraCreatureインスタンス変数にその値を設定できるようになりました。

      app.component.ts

      import {
        Component,
        ViewChild,
        AfterViewInit
      } from '@angular/core';
      import { SharkDirective } from './shark.directive';
      
      @Component({
        selector: 'app-root',
        templateUrl: './app.component.html',
        styleUrls: ['./app.component.css']
      })
      export class AppComponent implements AfterViewInit {
        extraCreature: string;
      
        @ViewChild(SharkDirective)
        set appShark(directive: SharkDirective) {
          this.extraCreature = directive.creature;
        };
      
        ngAfterViewInit() {
          console.log(this.extraCreature); // Dolphin
        }
      }
      

      ここではセッターを使用して、extraCreature変数を設定しました。AfterViewInitライフサイクルフックが変数にアクセスするのを待つことに注意してください。これは子コンポーネントとディレクティブが使用可能になったときです。

      ブラウザでアプリケーションを表示すると、引き続き「Shark Fin!」というメッセージが表示されます。ただし、コンソールログでは、次のように表示されます。

      Output

      Dolphin

      親コンポーネントは、ディレクティブから値にアクセスできました。

      DOM要素に対してViewChildを使用する

      ViewChildを使用すると、テンプレート参照変数を持つネイティブなDOM要素にアクセスすることができます。

      #someInput参照変数を持つ<input>がテンプレートにあるとします。

      app.component.html

      <input #someInput placeholder="Your favorite sea creature">
      

      これで、ViewChildを使用して<input>にアクセスし、を設定できます。

      app.component.ts

      import {
        Component,
        ViewChild,
        AfterViewInit,
        ElementRef
      } from '@angular/core';
      
      @Component({
        selector: 'app-root',
        templateUrl: './app.component.html',
        styleUrls: ['./app.component.css']
      })
      export class AppComponent implements AfterViewInit {
        @ViewChild('someInput') someInput: ElementRef;
        ngAfterViewInit() {
          this.someInput.nativeElement.value="Whale!";
        }
      }
      

      ngAfterViewInitが起動すると、<input>の値は次のように設定されます。

      Output

      Whale!

      親コンポーネントは、子のDOM要素の値を設定することができました。

      子コンポーネントに対してViewChildを使用する

      ViewChildを使用すると、子コンポ―ネントにアクセスしてメソッドを呼び出したり、子が使用可能なインスタンス変数にアクセスすることができます。

      ChildComponentがあるとします。理想的には、@angular/cliを使用してコンポーネントを生成します。

      • ng generate component child --flat

      それ以外の場合は、child.component.csschild.component.htmlファイルを作成し、app.module.tsに手動で追加する必要があります。

      app.module.ts

      import { ChildComponent } from './child.component';
      ...
      @NgModule({
        declarations: [
          AppComponent,
          ChildComponent
        ],
        ...
      })
      

      メッセージを返すChildComponentwhoAmIメソッドを追加します。

      child.component.ts

      whoAmI() {
        return 'I am a child component!';
      }
      

      次に、アプリテンプレート内のコンポーネントを参照します。

      app.component.html

      <app-child>child works!</app-child>
      

      これで、次のようにViewChildを使用して、親コンポーネントクラスからwhoAmIメソッドを呼び出すことができます。

      app.component.ts

      import {
        Component,
        ViewChild,
        AfterViewInit
      } from '@angular/core';
      import { ChildComponent } from './child.component';
      
      @Component({
        selector: 'app-root',
        templateUrl: './app.component.html',
        styleUrls: ['./app.component.css'],
      })
      export class AppComponent implements AfterViewInit {
        @ViewChild(ChildComponent) child: ChildComponent;
        ngAfterViewInit() {
          console.log(this.child.whoAmI()); // I am a child component!
        }
      }
      

      ブラウザでアプリケーションを表示すると、コンソールログに次のように表示されます。

      Output

      I am a child component!

      親コンポーネントは、子コンポーネントのwhoAmIメソッドを呼び出すことができました。

      まとめ

      ViewChildを使用して、親コンポーネントクラスからディレクティブ、子コンポーネント、DOM要素にアクセスする方法を学びました。

      参照が新しい要素に動的に変更された場合は、ViewChildによってその参照は自動的に更新されます。

      複数の子にアクセスしたい場合は、代わりにViewChildrenを使用します。

      Angular の詳細については、Angular トピックページで演習とプログラミングプロジェクトをご覧ください。



      Source link