2016年9月10日 星期六

解決在ng-repeat中radio未更新ng-model

原先寫法如下,確發生不管怎麼點selectedArea都不會更新
<label ng-repeat="area in areas">
    <input type="radio" ng-model="selectedArea" ng-value="area.Code"> {{area.Name}}
</label>
因為ng-repeat會產生自己的scope所以須使用$parent
<label ng-repeat="area in areas">
    <input type="radio" ng-model="$parent.selectedArea" ng-value="area.Code"> {{area.Name}}
</label>

2016年7月21日 星期四

讓 Web Api 輸出 JSON 格式

Web Api預設會優先輸出XML
有個偷吃步的方法就是乾脆讓程式不支援XML輸出
只要在Global.asax.cs的Application_Start()中加入以下程式碼即可

GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();