HTML5¼¼Êõ

ÔÚVisual Studio 2017ÖÐʹÓÃAsp.Net Core¹¹½¨Angular4Ó¦ÓóÌÐò - SmallProg(3)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-07-08 16:01 ÎÒÒªÆÀÂÛ( )

ÔÚ¿ª·¢µÄ¹ý³ÌÖУ¬ÎÒÃÇ»áÓõ½AngularCLIÃüÁîÖÐµÄ ng serve ÃüÁîÀ´ÆôÓÃAngularµÄ¼à¿Ø·þÎñģʽ¡£Ëû»á¼à¿ØAngularµÄÔ´Âë±ä»¯£¬µ±Ô´Âë±»¸Ä±äʱ£¬×Ô¶¯ÖØбàÒëAngular³ÌÐò²¢±àÒëTypeScript´úÂ롣ĬÈÏÇé¿öÏÂng serveÌṩµÄ

ÔÚ¿ª·¢µÄ¹ý³ÌÖУ¬ÎÒÃÇ»áÓõ½AngularCLIÃüÁîÖÐµÄ ng serve ÃüÁîÀ´ÆôÓÃAngularµÄ¼à¿Ø·þÎñģʽ¡£Ëû»á¼à¿ØAngularµÄÔ´Âë±ä»¯£¬µ±Ô´Âë±»¸Ä±äʱ£¬×Ô¶¯ÖØбàÒëAngular³ÌÐò²¢±àÒëTypeScript´úÂ롣ĬÈÏÇé¿öÏÂng serveÌṩµÄÊÇlocalhost:4200µØÖ·¡£

²¢ÇÒAngularĬÈϽÓÊÜRequestµÄµØַΪlocalhost:4200/api£¬ÕâÓëÎÒÃÇAsp.Net CoreĬÈϵÄlocalhost:5000²»Ò»Ñù¡£

ËùÒÔÎÒÃÇҪͨ¹ýÅäÖÃproxyÀ´½â¾öÕâ¸öÎÊÌâ¡£

Ê×ÏÈÔÚÏîÄ¿¸ùĿ¼ÖÐÌí¼ÓÒ»¸öjsonÎļþ£¬È¡Ãû×Ö½Ðproxy.config.json

image

ΪÕâ¸öÎļþÌí¼ÓÈçÏÂÅäÖôúÂë

image

{ : { : , : false } }

2. ÆôÓÃAsp.Net Core×Ô¶¯±àÒë

Èç¹ûAngularÄܹ»×Ô¶¯½øÐиü¸ÄÖرàÒëÔËÐУ¬²¢ÇÒAsp.Net CoreÒ²ÄÜÓüà¿Ø¸ü¸Ä×Ô¶¯ÖرàÒ룬ÄǾø¶ÔÊÇÎÒÏëÒªµÄ¡£

ÆôÓÃAsp.Net Core×Ô¶¯ÖرàÒ룬ÐèÒªÐÞ¸Ä.csprojÎļþ£¬Ìí¼ÓÒ»¸öDotNetCLI¹¤¾ß°ü¡£´úÂëÈçÏ£º

image

±£´æÎļþºó£¬VS»á×Ô¶¯»¹Ô­°²×°Õâ¸ö°ü¡£Èç¹ûûÓÐ×Ô¶¯»¹Ô­£¬ÇëʹÓÃDotNetCLIÃüÃû»¹Ô­°ü£º

dotnet restore

3. ÒÔ¼à¿ØģʽͬʱÔËÐÐAngularºÍAsp.Net Core

ʹÓÃPowerShell»òCMDÃüÁîÐй¤¾ß£¬ÔËÐÐÈçÏÂÃüÁîÒÔ¼à¿ØģʽÆôÓÃAsp.Net Core·þÎñÆ÷

dotnet watch run

image

´ò¿ªÁíÒ»¸öPowerShell»òCMDÃüÁîÐй¤¾ß£¬ÒÔ¼à¿ØģʽÅäÖÃÎļþÔËÐÐAngular

ng serve --proxy-config proxy.config.json

image

ÏÖÔÚÈÃÎÒÃÇ´ò¿ªä¯ÀÀÆ÷£¬·ÃÎÊ:4200

image

´ò¿ªValuesContoller£¬ÈÃÎÒÃǸü¸ÄһЩ¶«Î÷£º

image

´ò¿ªClientApp/app/app.component.htmlÎļþ£¬¸ü¸ÄһЩ¶«Î÷£º

image

±£´æÉÏÃæÁ½²½µÄ¸ü¸Äºó£¬»Øµ½ä¯ÀÀÆ÷£¬Äã»á¾ªÆæµÄ·¢ÏÖ£¬Asp.Net CoreºÍAngularµÄ´úÂë±ä¸üÒѾ­ÉúЧÁË

image


OK ,ÖÁ´Ë£¬Ê¹ÓÃÔÚVisual Studio 2017ÖÐʹÓÃAsp.Net Core¹¹½¨Angular4Ó¦ÓóÌÐò׫дÍê±Ï¡£

Ï£Íû±¾ÎĶÔÄãÓÐËù°ïÖú

תÔØÇëÖøÃû³ö´¦£º

Èç¹ûÓÐÄÄλ´óÉñÖªµÀ¸üºÃµÄ²¢ÐÐÔËÐнâ¾ö·½°¸£¬ÇëΪÎÒÁôÑÔ»òÁªÏµÎÒ£¬ÔÙ´ÎÏÈÐÐл¹ý~

×îºó¸½Éϱ¾ÏîÄ¿µÄÔ´Â룺¡¡https://github.com/smallprogram/AspNetCoreWithAngular4¡¡£¬ÐèÒªÊÖ¹¤»¹Ô­NPMŶ¡«

ÇëÇ󲩿ÍÔ°µÄ³¬¹Ü¸ø¼Ó¸ö¾«~

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • 2017ÄêÇ°¶Ë¿ò¼Ü¡¢Àà¿â¡¢¹¤¾ß´ó±ÈÆ´ - ÆÏÌѳǿؼþ¼¼ÊõÍŶÓ

    2017ÄêÇ°¶Ë¿ò¼Ü¡¢Àà¿â¡¢¹¤¾ß´ó±ÈÆ´ - ÆÏÌѳǿؼþ¼¼ÊõÍŶÓ

    2017-06-20 12:00

  • DIV CSS3´¦ÀíÔªËØÖصþ - yueyang2017

    DIV CSS3´¦ÀíÔªËØÖصþ - yueyang2017

    2017-05-22 11:01

  • DIV ÐÐÄÚ¹ØÁª box-shadow¶ÔÏóºÐ×ÓÒõÓ°ÒÔ¼°Í¼Æ¬ÒõÓ° - yueyang2017

    DIV ÐÐÄÚ¹ØÁª box-shadow¶ÔÏóºÐ×ÓÒõÓ°ÒÔ¼°Í¼Æ¬ÒõÓ° - yueyang2017

    2017-05-22 10:00

  • ΢Èí Build 2017 ¿ª·¢Õß´ó»á£ºAzure Óë AI µÄ¿ìËÙ·¢Õ¹ - ÆÏÌѳǿؼþ¼¼ÊõÍŶÓ

    ΢Èí Build 2017 ¿ª·¢Õß´ó»á£ºAzure Óë AI µÄ¿ìËÙ·¢Õ¹ - ÆÏÌѳǿؼþ

    2017-05-13 13:01

ÍøÓѵãÆÀ
þ