我有一个angularjs代码:
$scope.service = {}
$scope.editServiceModal = function (param1, param2) {
$scope.service = { "obj1": param1, "obj2": param2 }
$("#editModal").modal('show')
}
但是当我尝试以service.param1
和service.param2
的形式在html上调用它时,我没有得到任何回报。我尝试打印服务对象,但得到的只是一个空的json对象。
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" ng-controller="HmoServiceListCtrl">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Edit {{service.name}} service</h4>
</div>
<div class="modal-body">
<form class="form-horizontal ng-pristine ng-valid" name="editServiceForm" id="editServiceForm">
<div class="row" style=" margin-left: 0px;">
<div class="col-md-12">
<div class="form-group">
<label for="newName" class="col-md-3 ">Name</label>
<div class="col-md-9">
<input type="text" class="form-control" placeholder="Enter Service Name" ng-model="service.name" required>
</div>
</div>
<div class="form-group">
<label for="newPassword" class="col-md-3">Type</label>
<div class="col-md-9">
<ui-select ng-model="service.type_code" required theme="bootstrap">
<ui-select-match placeholder="Type">
<span>{{$select.selected.name}}</span>
</ui-select-match>
<ui-select-choices repeat="item.code as item in (types | filter: $select.search) track by item.code" required>
<span>{{item.name}}</span>
</ui-select-choices>
</ui-select>
</div>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" ng-click="editService()">Save changes</button>
</div>
</div>
</div>
</div>
答案 0 :(得分:0)
这是我的一个项目的摘要:
vm.VersionClick = function () {
var element = angular.element("#ChangeLog");
element.modal('show');
}
“ vm”在这种情况下是作用域,在文件顶部,我像这样初始化vm:
function sidebar($route, config, routes,datacontext, $scope, $rootScope) {
var vm = this;
然后在整个页面/ js文件中,我可以使用“ vm”。对于自身内部的一切。
摆脱jquery的东西,你应该没事。
祝你好运!