如何在angularjs中过滤ng-model

时间:2017-08-25 07:47:45

标签: angularjs twitter-bootstrap asp.net-web-api2

我正在使用webapi 2开发角度应用程序,输入表单包含输入值。我将输入值封装到对象“ALBUM”传递给angular post方法

enter code here



 <form>
            <div class="form-group row">
                <label for="inputAName" class="col-sm-3 col-form-label">Album Name</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" id="inputEmail3" placeholder="AlbumName" ng-model="album.Albm_Name">
                </div>
            </div>
            <div class="form-group row">
                <label for="inputPassword3" class="col-sm-3 col-form-label">Music Artist</label>
                <div class="col-sm-8">
                    <select ng-model="album.Aritist_id">
                        <option ng-repeat="Artist in  Artists" value="{{Artist.Artist_id}}">{{Artist.Artist_Name}}</option>
                    </select>
                </div>

            </div>

            <div class="form-group row">
                <label for="inputRdate" class="col-sm-3 col-form-label">Released Date</label>
                <div class="col-sm-8">
                    <input type="date" class="form-control" id="inputPassword3" placeholder="date" ng-model="album.RelaeseDate">
                </div>
            </div>

            <div class="form-group row">
                <label for="inputImg" class="col-sm-3 col-form-label">Image of Album</label>
                <div class="col-sm-8">
                    <input type="file" class="form-control-file" id="exampleInputFile" aria-describedby="fileHelp" name="file"
                           ng-model="album.picture" base-sixty-four-input required onload="onLoad" maxsize="500" accept="image/*">

                </div>
            </div>for

            <div class="form-group row">
                <div class="col-sm-offset-9 col-sm-2">
                    <button type="submit" class="btn btn-primary" ng-click="insertAlbum(album)">Save</button>
                </div>
            </div>
        </form>

上面的代码,ng-model ='album.picture'返回一个包含更多值的对象“附加图像文件enter image description here

我需要过滤album.picture只包含base64字符串值,我该怎么做 不破坏视图中的相册对象

  $scope.insertAlbum = function (album) {
            var urlAlbum = 'http://localhost:8090/api/album';
            dataService.insertObject(urlAlbum, album).then(function (responce) {
                alert("Success");
            }, function (eror) {

                alert(eror.message);
            });
        }

 public partial class tblAlbum
{
    public tblAlbum()
    {
        this.tblTracks = new HashSet<tblTrack>();
    }

    public int Albm_id { get; set; }
    public Nullable<int> Aritist_id { get; set; }
    public string Albm_Name { get; set; }
    public Nullable<System.DateTime> RelaeseDate { get; set; }
    public byte[] picture { get; set; }

    public virtual tblArtist tblArtist { get; set; }
    public virtual ICollection<tblTrack> tblTracks { get; set; }
}

1 个答案:

答案 0 :(得分:0)

我发现了一个解决方案 这是:

$scope.insertAlbum = function (album) {
            var urlAlbum = 'http://localhost:8090/api/album';
            album.picture = $scope.file.base64;
            dataService.insertObject(urlAlbum, album).then(function (responce) {
                alert("Success");
            }, function (eror) {

                alert(eror.message);
            });
        } 

手动我使用$ scope

创建了一个picture属性和asigned views输入值