john papaスタイルを使用して角度アプリを開発しています。そのため、コントローラはサービスを使用して別のコントローラにデータを渡しています。 2番目のコントローラでは、コントローラがコールを取得したときに入力フィールドの値を設定します。私はそれを設定しようとしましたvmをコントローラとして使用する場合の入力フィールドの初期値の設定方法は?
vm.form.mobile = getMob[1].mobile;
これは私のためには機能しませんでした。ここで
は私の第二のコントローラここ
(function()
{
'use strict';
angular
.module('app.pages.auth.verify-mobile')
.controller('VerifyMobileController', VerifyMobileController);
/** @ngInject */
function VerifyMobileController($scope,dataservice,msApi, $state,$mdDialog)
{
var vm = this;
window.onbeforeunload = function() {
$state.go('app.pages_auth_login');
}
var getMob = dataservice.getData();
if(typeof getMob !== 'undefined'){
vm.form.mobile = getMob[1].mobile;
}
}
}();
されるHTML要素
<form name="verifyMobileForm" novalidate>
<md-input-container class="md-block" md-no-float>
<input type="mobile" id="mobile" name="mobile" ng-model="vm.form.mobile" placeholder="Your Mobile number" ng-pattern="/^[789]\d{9}$/" maxlength="10" required>
<div ng-messages="verifyMobileForm.mobile.$error" role="alert" multiple>
<div ng-message="required">
<span >Mobile no. is required</span>
</div>
</div>
</md-input-container>
<div class="dialog-demo-content" layout="row" layout-wrap layout-margin layout-align="center">
<md-button type="submit" class="md-raised md-accent submit-button" ng-disabled="verifyMobileForm.$invalid || verifyMobileForm.$pristine" ng-click = "vm.checkMobile($event, document.getElementById('mobile').value)">
Next
</md-button>
</div>
</form>
コンソールでこのエラーが発生しました – ocespedes