使用ng-include时无法获取值?

时间:2015-04-12 10:49:41

标签: angularjs

我的 Employee.cshtml

<html ng-app="crudModule">
@{
    ViewBag.Title = "Index";
}

<head> 
</head>
<h2>Employee List</h2>
<h2>===================</h2>
<body>

    <div ng-controller="employeeController">
        <table cellspacing="0" cellpadding="0">
            <tr>               
                <td><div ng-include="'/Content/EmployeeInfo/employee.html'"></div></td>
                <td><div ng-include="'/Content/EmployeeInfo/department.html'"></div></td> 
                <td><div ng-include="'/Content/EmployeeInfo/EmployeeDepartmentOperations.html'"></div></td> 
            </tr>
        </table>            
    </div>         
</body>
</html>
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-route.js"></script>
<script src="~/Scripts/MyScripts/Module.js"></script>
<script src="~/Scripts/MyScripts/Controllers/ITOps/ITOpsController.js"></script>

EmployeeDepartmentOperations.html

<table border="1">
        <tr>
            <td>EmployeeId</td>            
        </tr>
        <tr>
            <td><input type="text" id="empID" ng-model="EmployeeId" /></td>           
        </tr>
    </table>
    <input type="button" id="txtInsertEmployeeDept" value="Insert Employee & Department" ng-click="InsertEmployeeDepartment()" />

控制器

app.controller('employeeController', function ($scope, crudService) {  


        $scope.InsertEmployeeDepartment = function () {

            alert($scope.EmployeeId);           
        }   
});

但是我无法获得 $ scope.EmployeeId。 它将作为未定义

为什么?我在做什么错误?

1 个答案:

答案 0 :(得分:0)

是的,@ Alex和@Nitsan都指出了我正确的方向。我需要做

 ng-model="$parent.EmployeeId"

感谢你们两位。