Angular CLI time out in .Net Core Project
I created the first project in Visual Studio 2019 in Mac. I have no problems, but when I tried to run it in my Windows box. But I got a runtime error for Angular CLI Timeout. I got exact same code of mac version. There should be no problems. After some investigations, because my windows box is old, that is a five year old laptop. Although mac book pro is 6 year old too, but that is still running better than my windows box. Thus, the angular CLI still can compile the client front end within the default angular cli timeout amount. Therefore, I just need to increase the timeout for Angular CLI. Then I tried it, to increase the timeout of Angular CLI, you need to change startup.cs at the root level of project. please add this line of code after spa.UseAngularCliServer(npmScript: "start"); (should be line 70)
spa.Options.StartupTimeout = TimeSpan.FromSeconds(500);
Then my project is working
Authentication for Angular .Net Core Project
I have used Angular since .Net Core 2.2. In the past, I still can use identity framework core but you have to link the Angular with your api by yourself, you need to jwt serialization. But in the .net Core 3 with Visual Studio 2019, you need to create the angular project with by selecting the individual user account. Then the basic identity framework core structure will be generated for you. The user login and registration user page are generated. That is so easy and saved at least an hour work for me too!
Wi-Fi debugging in xarmain
I got an old MacBook Pro which only has two USB ports. I used an external keyboard and mouse. Both require USB ports. They left no room to connect a phone for debugging. Recently, I found there is a feature in visual studio. This new feature allows the developers to connect the devices via wifi. This measure can free up USB ports. Moreover, this method can do the debugging wireless, that is more convenient, I can carry the debugging device around and without wires, which can keep my desk cleaner.
Although it said that is wireless, you still need to connect with USB and open the device windows in the XCode. Then you need to check the box to enable wifi debug. After that, that is very easy. You select the device in Visual Studio when the device connected to the same wifi networks.
Send JSON from AngularJS to ASP.Net Core
I found that is anulgarjs and ASP.net Core are working very well together!
In the client side:
var Item = {};
Item.Id = 1;
Item.Name = "Test";
$http.post('/Items/Create', Item);
In the server side controller, then the JSON object can automatic parsed.
You just need to use [FromBody], I found without that, the parameter object will be always null. I think you need to tell the MVC, where is the JSON content:
[HttpPost]
[Authorize]
public async Task
That's easy and clean!
ASP.Net Core MVC Validations are not working , after added a click event in the submit button
I added a click event in the submit button to display a confirmation message:
$("#btnSubmit").click(function () {
alert("An event is clicked");
});
That broke all client-side validations of ASP.Net Core MVC, however, the server side validations is still working. You cannot submit an event with invalid data, but it won't display the errors messages.
I tried to add the javascript code in the submit event in form instead of the click event of the event, that is not working too. Even I added another invisible submit button, after the confirmation message is displayed, then the code will trigger the click event of that invisible submit button. That is still not working.
I randomly placed the script tags. I found the script file which contains the click event needs to place after the validation scripts:
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script><script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>