This should work fine; the installer will install all drivers needed for all supported Mac models, so you can move drives between models pretty freely.
Update: Starting with High Sierra, this is no longer supported. The OS itself will be fine, but unless you run the High Sierra installer on that computer, and with a live Internet connection, the computer's firmware may not be properly updated to support the new OS. According to Apple support article HT208020:
If you try to use a monolithic system image [equivalent to
transferring an HD with the OS installed], required firmware updates
will be missing from the installation. This causes the Mac to operate
in an unsupported and unstable state.
See this TidBITS article for more info.
BTW, just to give you some idea of the possibilities for trouble: there was an issue with Mac OS X v10.2 (yes, long ago) where if you installed it on an iMac DV model that hadn't had its firmware updated, it did something bad to the video configuration, and the display would be blank. The display would remain blank, even if you booted back into an older version. This made it really hard to run the firmware updater and make the computer usable again. I was working in a repair shop at the time, and we had a lot of iMacs come in with this problem.
I suspect the current firmware compatibility worries have to do with compatibility with the new APFS volume format, so the worst that should happen is that an un-updated Mac won't be able to boot from a High Sierra volume in APFS format. Probably. Maybe. No promises, though.