AngularJS表单未加载

时间:2016-03-07 12:42:37

标签: javascript jquery html angularjs visual-studio

我正在研究Angular表单。我创建了Index.htmlefTemplate.html个文件。 efTemplate.html是一个表单页面,我试图进入Index.html。我正在使用Index.html页面,其中包含所需的所有脚本语言参考。我执行Index.html时仍然是空白页面。 请建议。

代码

  

的index.html

<!DOCTYPE html>
<html ng-app="angularFormsApp">
<head>
<title></title>
<link href="Content/bootstrap.min.css" rel="stylesheet" />
<script src="Scripts/angular.min.js"></script>
<script src="app/AngularFormsApp.js"></script>
<script src="app/EmployeeForm/efController.js"></script>
<script src="app/EmployeeForm/efDirective.js"></script>
<script src="app/EmployeeForm/efService.js"></script>
</head>
<body ng-controller="efController" class="container">
   <employee-form />
</body>
</html>

代码

  

AngularFormsApp.js

var angularFormsApp = angular.module('angularFormsApp', []);

代码

  

efController.js

angularFormsApp.controller('efController',
function efController($scope, efService) {
    $scope.employee = efService.employee;
});

代码

  

efService.js

angularFormsApp.factory('efService',
function () {
    return {
        employee:{
            fullName: "Ashok Karale",
            Notes: "The Ideal employee. Just don't bother him",
            department: "Admin",
            perkCar: true,
            PerkStock: false,
            perkSixWeeks:true,
            PayrollType:"none"
        }
    }
});

代码

  

efDirective.js

angularFormsApp.directive('employeeForm',
function () {
    return {
        restrict: 'E',
        templateUrl: 'app/EmployeeForms/efTemplate.html'
    }
});

的代码
  

efTemplate.html

<form role="form">
<div class="form-group">
    <label for="fullName">Name</label>
    <input type="text" id="fullName" class="form-control" />
</div>

<div class="form-group">
    <label for="notes">Notes</label>
    <textarea name="notes" id="notes" class="form-control" rows="5">   </textarea>
</div>
<div class=" form-group">
    <label for=" department">Department</label>
    <select name="department" id="department" class="form-control">
        <option>Engineering</option>
        <option>Finance</option>
        <option>Admin</option>
    </select>
</div>
<br />
<span><b>Perks</b></span><br />
<div class="checkbox">
    <label><input type="checkbox" value="perkCar"/>PerkCar</label>
</div>
<div class="checkbox">
    <label><input type="checkbox" value="perkStock" />PerkStock</label>
</div>
<div class="checkbox">
    <label><input type="checkbox" value="perSixWeek" />Perk SixWeek</label>
</div>

<div class="radio">
    <label><input type="radio" name="payrollType" value="w2" />W-2</label>
</div>
<div class="radio">
    <label><input type="radio" name="payrollType" value="ten99" />W-2</label>
</div>
<div class="radio">
    <label><input type="radio" name="payrollType" value="none" />W-2</label>
</div>
<br />
<input type="submit"class="btn btn-primary" value="Submit" />
</form>

1 个答案:

答案 0 :(得分:0)

我认为放置指令标签的正确方法是:

<employee-form></employee-form>

https://docs.angularjs.org/guide/directive