小编Jos*_*ssi的帖子

然后AngularJS加载服务调用控制器并进行渲染

我的问题是我需要在调用控制器并呈现模板之前加载服务. http://jsfiddle.net/g75XQ/2/

HTML:

<div ng-app="app" ng-controller="root">
    <h3>Do not render this before user has loaded</h3>            
    {{user}}
</div>
?
Run Code Online (Sandbox Code Playgroud)

JavaScript的:

angular.module('app', []).
factory('user',function($timeout,$q){
    var user = {};            
    $timeout(function(){//Simulate a request
        user.name = "Jossi";
    },1000);
    return user;
}).
controller('root',function($scope,user){

    alert("Do not alert before user has loaded");
    $scope.user = user;

});
?
Run Code Online (Sandbox Code Playgroud)

javascript synchronization sync angularjs

21
推荐指数
2
解决办法
4万
查看次数

AngularJS指令转换scope = false?

如何通过transclude来防止指令创建新的范围?

这个jsfiddle我不能绑定任何东西,因为新的范围用红色边框说明.

HTML:

<div ng-app="components">
    <input ng-model="var">
    <block>
        123
        <input ng-model="var">
    </block>
</div>
Run Code Online (Sandbox Code Playgroud)

JavaScript的:

angular.module('components', []).directive('block',function(){
    return{
        scope:false,
        replace:true,
        restrict:"E",
        transclude:true,
        template:'<div class="block" ng-transclude></div>',
        link:function(scope, el, attrs, ctrl){

        }
    }
});
Run Code Online (Sandbox Code Playgroud)

CSS:

.ng-scope{
  border:1px solid red;
    margin:10px;
}
Run Code Online (Sandbox Code Playgroud)

html javascript binding angularjs

6
推荐指数
1
解决办法
5926
查看次数

如何在Ada中实现界面?

不知道这个oop模式叫什么,但我怎么能在Ada中做同样的模式?例如这段代码:

interface Vehicle{
    string function start();
}

class Tractor implements Vehicle{
    string function start(){
        return "Tractor starting";
    }
}
class Car implements Vehicle{
    string function start(){
        return "Car  starting";
    }
}

class TestVehicle{
    function TestVehicle(Vehicle vehicle){
        print( vehicle.start() );
    }
}
new TestVehicle(new Tractor);
new TestVehicle(new Car);
Run Code Online (Sandbox Code Playgroud)

我在Ada失败的尝试: 如何妥善解决?

with Ada.Text_IO;

procedure Main is

   package packageVehicle is
      type Vehicle is interface;
      function Start(Self : Vehicle) return String is abstract;
   end packageVehicle;

   type Tractor is new packageVehicle.Vehicle with null record;
   overriding …
Run Code Online (Sandbox Code Playgroud)

oop interface ada

5
推荐指数
2
解决办法
3226
查看次数

如何在ada中分配除one之外的所有元素?

如何在ada中分配除one之外的所有元素?

如果我有这个

element_to_ignore : integer := 3;
a : array(1..4) := (5,3,2,6);
b : array(1..a'length-1) := a( all but element_to_ignore );
Run Code Online (Sandbox Code Playgroud)

我需要这个结果:
b =(5,3,6)

ada

2
推荐指数
1
解决办法
176
查看次数

缺少Ada记录的功能

考虑遵循C++代码:

class Person
{
public:
    const std::string Name;
    int Weight = 0;
    Person(std::string AssignName) : Name(AssignName)
    {}
};

void Dinner(Person & ModifyPerson)
{
    ModifyPerson.Weight += 2;
}
Run Code Online (Sandbox Code Playgroud)

名称是常量,并且在创建Person时首先初始化.重量可以修改.

Person Person0("Conny");
Dinner(Person0);
Run Code Online (Sandbox Code Playgroud)

让我们在Ada中试试这个:

type Person is record
    Name : constant String;
    Weight : Integer := 0;
end record;

Person0 : Person := Person'(Name => "Abby");
Run Code Online (Sandbox Code Playgroud)

的名字应该永远是'艾比’,因为它常和重量应该是修改和0作为defualt.

不起作用,因为Ada记录不允许以下内容:

  • 恒定场
  • 字段类型的未指定范围
  • 限制初始化列表,即仅分配名称,并且权 = 0作为默认值.

如何在Ada代码中执行C++代码?

在C++中,我可以通过派生来扩展Person.在Ada中,我们使用标记记录.但标记记录也不起作用.

如何使用Person的可扩展功能在Ada代码中执行C++代码?

c++ initialization constants record ada

0
推荐指数
2
解决办法
429
查看次数

使用函数代替过程来初始化派生类型

如何Base使用函数从类型初始化派生类型?

如果我可以使用function Create而不是程序,它看起来会更好.

procedure Main is

   type Base is abstract tagged record
      Number : Integer;
   end record;

   type Base1 is new Base with null record;
   type Base2 is new Base with null record;

   --function Create return Base'Class is
   --begin
      --return (Number => 1);
   --end;

   procedure Create ( B : out Base'Class ) is
   begin
      B.Number := 1;
   end;

   B1 : Base1;
   B2 : Base2;

begin

   Create (B1);
   Create (B2);

end Main;
Run Code Online (Sandbox Code Playgroud)

取消注释时的Builder结果function Create:

type …
Run Code Online (Sandbox Code Playgroud)

initialization ada derived

0
推荐指数
1
解决办法
90
查看次数