Welcome aboard! We are happy you are here and wish you good net-raft!
// You can get a hostname with angular this way:
// app.component.ts
import { Component, OnInit, Inject, Injectable } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
hostname:any;
domain:any;
constructor(@Inject(DOCUMENT) private document: any) { }
ngOnInit() {
this.domain = this.document.location.hostname;
this.hostname = this.domain;
}
}
// app.component.html
<div style="text-align:center">
<h1>
{{hostname}}
</h1>
</div>
// this is the only solution, works only for IE in intranet or local machine, there is a security reason
// you can try node.js https://net-raft.com/Questions/1567/how-to-get-client-machine-name-and-computer-name-with-nodejs/1567
// important : ActiveXObject works only for IE (new ActiveXObject("ADODB.Connection"))
try
{
var ax = new ActiveXObject("WScript.Network");
alert('User: ' + ax.UserName );
alert('Computer: ' + ax.ComputerName);
}
catch (e)
{
alert('Permission to access computer name is denied');
}
});
// important : ActiveXObject works only for IE (new ActiveXObject("ADODB.Connection"))
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="//code.angularjs.org/snapshot/angular.min.js "></script>
</head>
<body ng-app="getname">
<script>
angular.module('getname', [])
.controller('myname', ['$scope', function ($scope) {
var ax = new ActiveXObject("WScript.Network");
$scope.name = 'User: ' + ax.UserName + ' Computer: ' + ax.ComputerName;
} ]);
</script>
<div ng-controller="myname">
<span>{{name}}</span>
</div>
</body>
</html>
The most helpful ANGULARJS solutions